jQuery选择不工作的内容​​通过AJAX加载加载、内容、工作、jQuery

2023-09-10 18:58:33 作者:梦里梦外都是他

我有以下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