Vis*_*hu7 6 ajax firefox html5 autofocus
下面是我通过ajax加载的表单.当我直接运行表单页面然后自动对焦c_name在Firefox中工作但是当加载ajax时它不会!虽然它与opera/safari/chrome一起工作正常!
<form action="client_entry_action.php" method="post" id="client_entry_form" name="client_entry_form">
<fieldset id="client_info_1">
<label for="c_name">Name:</label>
<input type="text" name="c_name" required placeholder="Name" autofocus="autofocus" />
<label for="c_phone">Phone Number:</label>
<input type="tel" name="c_phone" required placeholder="Mobile/Phone Number" />
<label for="c_email">Email:</label>
<input type="email" name="c_email" required placeholder="email@example.com" />
<label for="c_address">Address:</label>
<textarea name="c_address" ></textarea>
</fieldset>
<fieldset id="client_info_2">
<label for="c_info">Additional notes:</label>
<textarea name="c_info" ></textarea>
<input type="submit" name="add_client" value="Add Client" />
</fieldset>
</form>
Run Code Online (Sandbox Code Playgroud)
自动对焦仅在onload触发之前完成; 它意味着一种声明性的方式来指定对初始页面加载的关注.
在对div调用ajax之后使用settimeout,或者使用jquery使用.ajaxComplete或.done
function theAjax(){
//after the ajax actions loaded......
//use settimeout to refocused on the input..
var t=setTimeout("focusMe()",500);
Run Code Online (Sandbox Code Playgroud)
}
function focusMe(){
document.getELementById("theInput").focus(); //the new input
Run Code Online (Sandbox Code Playgroud)
}
//using jquery use .ajaxComplete, or .done
$( document ).ajaxComplete(function() {
$("#focusOnMe").focus();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16798 次 |
| 最近记录: |