jQuery选择不工作的内容​​通过AJAX加载 [英] Jquery selector not working on content loaded through ajax

查看:130
本文介绍了jQuery选择不工作的内容​​通过AJAX加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下code派单选按钮的人通过AJAX已经点击的价值。但是,但是只适用于第一套方案,我给。在用户preSS下一个环节后,所有的选项都改变了,并通过AJAX新loaeded。但在这个选择是行不通的。

  $(选项输入)。点击(函数(){
VAR ANS = $(本).VAL();

$。员额(会议,{行动:set_answer,回答:答,问题:QID},
功能(数据){
 警报(数据加载:+数据);
});


});
 

什么是可能的解决办法?下面的选项是如何。

 < D​​IV CLASS =选项>
<输入ID =1类型=无线电名称=回答值=二/>二< BR />
<输入ID =2类型=无线电名称=回答值=一/>一个实施; BR />
<输入ID =3类型=无线电名称=回答值=四/>四< BR />
<输入ID =4类型=无线电名称=回答值=十二五/>五< BR />
<输入ID =5类型=无线电名称=回答值=六/>六< BR />
< / DIV>
 

解决方案

如果最新的jQuery,


$('选择输入')。在('点击',函数(事件){
....

或者你可以尝试这样做:


$(选项输入)。生活(点击,函数(){
....

希望它可以帮助

I am having below code to send the value of radio button people have clicked via ajax. But it however only works on the first set of options I give. After the the user press next link and all the options are changed and new one loaeded through ajax. But on that this selector is not working.

$(".options input").click(function(){
var ans = $(this).val();

$.post("sessions", { action: "set_answer", answer: ans, question: qid  },
function(data) {
 alert("Data Loaded: " + data);
});


});

What is the possible solution? Below is how the options are.

<div class="options">
<input id="1"type="radio" name="answer"  value="Two" />Two<br/>
<input id="2"type="radio" name="answer"  value="One"  />One<br/>
<input id="3"type="radio" name="answer"  value="Four"  />Four<br/>
<input id="4"type="radio" name="answer"  value="Five"  />Five<br/>
<input id="5"type="radio" name="answer"  value="Six"  />Six<br/>    
</div>

解决方案

If latest jQuery,


$('.options input').on('click', function(event) {
....

Or you could try doing:


$(".options input").live("click", function(){
....

Hope it helps

这篇关于jQuery选择不工作的内容​​通过AJAX加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆