jQuery的焦点不工作在一个页面加载Ajax [英] jquery focus not working on a page loaded with ajax
本文介绍了jQuery的焦点不工作在一个页面加载Ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码
index.php
<!DOCTYPE html>
< head>
< script src =// ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js\"></script>
< / head>
< body>
< script>
$(document).ready(function(){
$(#verifica)。click(function(){
$(#risultati)。html ...);
$ .ajax({
type:POST,
url:go.php,
data:$(#ciao) .serialize(),
dataType:html,
成功:函数(msg)
{
$(#risultati)。html(msg);
error:function()
{
$(#risultati)。html(An error occurred。);
}
}) ;
});
});
< / script>
< form name =ciaoid =ciaoaction =#>
< input type =textid =zioname =zio>
< input type =submitonclick =return:false; name =verificaid =verificavalue =go>
< / form>
< div id =risultati>< / div>
< / body>
go.php
<!DOCTYPE html>
< head>
< meta http-equiv =content-typecontent =text / html; charset = iso-8859-1>
< / head>
< body>
< script>
$(#zio)。focus();
< / script>
< / body>
应该做什么
聚焦#当表单完全通过jquery提交给go.php时,zio。
什么是不工作
表单数据是我的问题
如何修复我的代码?
解决方案
由于您的Ajax代码知道所有有关输入(同一页)的内容,为什么不这样做呢:
success:function(msg)
{
$(#risultati)。html(msg);
$(#zio)。focus();
$ b $ p
$ b 你当前的版本有一个子页面有父页面的知识分离)。
My code
index.php
<!DOCTYPE html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<script>
$(document).ready(function() {
$("#verifica").click(function(){
$("#risultati").html("Please wait...");
$.ajax({
type: "POST",
url: "go.php",
data: $("#ciao").serialize(),
dataType: "html",
success: function(msg)
{
$("#risultati").html(msg);
},
error: function()
{
$("#risultati").html("An error occurred.");
}
});
});
});
</script>
<form name="ciao" id="ciao" action="#">
<input type="text" id="zio" name="zio">
<input type="submit" onclick="return:false;" name="verifica" id="verifica" value="go">
</form>
<div id="risultati"></div>
</body>
go.php
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<body>
<script>
$("#zio").focus();
</script>
</body>
What it should do
Focusing #zio when form has completely submitted to go.php via jquery.
What's not working
While form data is submitted, #zio is not focused.
My question
How can I fix my code?
解决方案 As your Ajax code knows all about the inputs (same page), why not just do this:
success: function(msg)
{
$("#risultati").html(msg);
$("#zio").focus();
},
Your current version has a child page has knowledge of the parent page (bad separation).
这篇关于jQuery的焦点不工作在一个页面加载Ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文