Jquery 多 ID 选择器不起作用
Jquery multiple ID selector doesn't work
我试过这个脚本,但对第二个给定的 ID 不起作用;
这两个元素都在 iframe
内
<script>
jQuery(document).ready(function(){
$("#subscribe_newsletter, #close_bar").each(function(){
$(this).click(function(){
alert("with each");
$.cookie( "nl_cookie" , 1 , { path: "/" } );
$("#footer_accept_newsletter").hide("slow");
});
});
cookieValue = $.cookie("nl_cookie" , { path: "/" });
if(!cookieValue){
$("#footer_accept_newsletter").removeClass("hidden");
}
});
</script>
我也尝试了以下代码但没有成功;
$("#subscribe_newsletter, #close_bar").click(function(){
$.cookie( "nl_cookie" , 1 , { path: "/" } );
$("#footer_accept_newsletter").hide("slow");
});
对我有用
$(document).ready(function(){
$("#segement1, #segement2, #segement3").click(function(){
alert($(this).attr("id"));
});
});
检查一下FIDDLE
我试过这个脚本,但对第二个给定的 ID 不起作用; 这两个元素都在 iframe
内<script>
jQuery(document).ready(function(){
$("#subscribe_newsletter, #close_bar").each(function(){
$(this).click(function(){
alert("with each");
$.cookie( "nl_cookie" , 1 , { path: "/" } );
$("#footer_accept_newsletter").hide("slow");
});
});
cookieValue = $.cookie("nl_cookie" , { path: "/" });
if(!cookieValue){
$("#footer_accept_newsletter").removeClass("hidden");
}
});
</script>
我也尝试了以下代码但没有成功;
$("#subscribe_newsletter, #close_bar").click(function(){
$.cookie( "nl_cookie" , 1 , { path: "/" } );
$("#footer_accept_newsletter").hide("slow");
});
对我有用
$(document).ready(function(){
$("#segement1, #segement2, #segement3").click(function(){
alert($(this).attr("id"));
});
});
检查一下FIDDLE