您现在的位置是:首页> 网站开发

layer中弹出层的内容点击事件不起作用

  • 3398人已阅读
  • 时间:2018-10-16 09:11:39
  • 分类:网站开发
  • 作者:祥哥

layer中弹出层的内容点击事件不起作用

  1. click只能为页面现有的元素绑定事件,如果是动态的新的元素,是没有事件的。

  2. 而$(document).on("click","指定元素",function(){});方法则是将指定的事件绑在document上,而新产生的元素如果符合指定的元素,那就触发此事件。

不起作用:

$('#test').on('click', function() {
    layer.msg('响应点击事件');
});

起作用:

$(document).on('click', '#test', function() {
    layer.msg('响应点击事件');
});

鼠标经过移出事件

不起作用

$("#openweixin").mouseover(function (){
    alert(1);
}).mouseout(function (){
    alert(2);
});

起作用

$(document).on('mouseover', '#openweixin', function() {
    $("#openweixin").css("background","yellow");
});
$(document).on('mouseout', '#openweixin', function() {
    $("#openweixin").css("background","white");
});


Top