下面是我通过AJAX加载的形式。当我直接运行表单页面,然后自动对焦的c_name在Firefox,但满载时AJAX不是!它正常工作与歌剧/ Safari /铬尽管!
<形式的行动=client_entry_action.php方法=后ID =client_entry_formNAME =client_entry_form>
&所述;字段集的id =client_info_1>
<标签=c_name>名称:< /标签>
<输入类型=文本名称=c_name要求的占位符=名称自动对焦=自动对焦/>
<标签=c_phone>电话号码:其中; /标签>
<输入类型所需=电话NAME =c_phone占位符=手机/电话号码/>
<标签=c_email>电子邮件:LT; /标签>
<输入类型=电子邮件NAME =c_email要求的占位符=email@example.com/>
<标签=c_address>地址:< /标签>
< textarea的名字=c_address>< / textarea的>
< /字段集>
&所述;字段集的id =client_info_2>
<标签=c_info>其他注意事项:其中; /标签>
< textarea的名字=c_info>< / textarea的>
<输入类型=提交名称=add_clientVALUE =添加客户端/>
< /字段集>
< /形式GT;
解决方案
使用的setTimeout的股利,或使用jQuery使用.ajaxComplete,或.done Ajax调用后
函数theAjax(){
//加载后的阿贾克斯行动......
//使用的setTimeout来重新聚焦在输入..
变种吨= setTimeout的(focusMe(),500);
}
函数focusMe(){
的document.getElementById(theinput的时候)专注()。 //新的输入
}
//使用jQuery使用.ajaxComplete,或.done
$(文件).ajaxComplete(函数(){
$(#focusOnMe)专注()。
}
Below is the form which i loaded via ajax. When i run the form page directly then autofocus on c_name works in firefox but when loaded with ajax it doesn't! It works fine with opera/safari/chrome though!
<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>
解决方案
use settimeout after ajax call on the div, or using jquery use .ajaxComplete, or .done
function theAjax(){
//after the ajax actions loaded......
//use settimeout to refocused on the input..
var t=setTimeout("focusMe()",500);
}
function focusMe(){
document.getELementById("theInput").focus(); //the new input
}
//using jquery use .ajaxComplete, or .done
$( document ).ajaxComplete(function() {
$("#focusOnMe").focus();
}