2012-08-24 71 views
-2

我的custom.js文件中有这两段脚本。第一个触发罚款。但第二个没有。我做错了什么,就像缺少支架或什么的?我试过JSLing,但无法弄清楚。谢谢你们jQuery脚本不会触发

$(document).ready(function() { 
    $(".SubmitWrapper").click(function() { 
     $(".SubmitWrapper").replaceWith('<div class="SubmitWrapper"><div class="Button_Submit2"><a onClick="" href=""><span>Please ..</span></a></div></div>'); 
     alert('fdsfds'); 
    }); 
}); 


$(document).ready(function() { 
    $(document).on('click', 'ul.NFSelectOptions li', 'a', function() { 
     if ($(this).text() == "Feedback") { 
      $('body').html("hihi"); 
      alert("Goodbye!"); 
     } 
    }); 
});​ 

回答

4

此行是错误的:

$(document).on('click', 'ul.NFSelectOptions li', 'a', function() { 

它应该是这样的:

$(document).on('click', 'ul.NFSelectOptions li a', function() { 

所有选择的作品去一个字符串,而不是在两个参数。你的方式把函数放在错误的参数中,所以它永远不会被调用。

+0

它没有工作。但第二个脚本自行完善。请参阅:http://jsfiddle.net/N5t6A/ – nasty

+1

@Uds - 你的jsFiddle中没有与选择器匹配的东西。没有ul标签,没有li标签,没有标签。请向我们展示所有相关的HTML。也许你的选择器也是错的。 – jfriend00

+0

@Uds在小提琴中,您再次使用_wrong_选择器! – undefined

0

合并它们。编辑:明白了。

$(document).ready(function(){ 
    $(".SubmitWrapper").click(function() { 
     $(".SubmitWrapper").replaceWith('<div class="SubmitWrapper"><div class="Button_Submit2"><a onClick="" href=""><span>Please ..</span></a></div></div>'); 
     alert('fdsfds'); 
    }); 
    $('form').on('click', 'ul li', 'a', function(){ 
     if($(this).text() == "Feedback"){ 
      $("#adminForm_1").html("hihi"); 
     } 
    }); 
}); 
+0

还是第二个不触发。 – nasty

+1

这是一个紧凑的建议,但与问题无关。 – jfriend00

+0

@它是你的选择。 ('click','ul li','a',function(){});' – mittmemo