我在普通的js文件中有这个js代码。
$('body').on('click','.close-modal',function(e) {
if ($('.modal-container').length > 1) {
$('.modal-container').last().remove();
$('.modal-window').last().remove();
}
else {
$('.modal-window, .modal-container').fadeOut(500).queue(function() { $('.modal-window, .modal-container').remove();});
}
e.preventDefault();
});我想用我的需求重写这段代码,因为它是通用的js文件,在common.js中做任何修改都不是好的做法。我的覆盖函数-
$('body').on('click','.close-modal',function(e) {
if(strText.length >0 {
if ($('.modal-container').length > 1) {
$('.modal-container').last().remove();
$('.modal-window').last().remove();
}
}
e.preventDefault();
});因为js文件调用了之前的,所以它没有调用我的更改...实现这一目标的任何选项。
StrText是我的json_enoded字符串。
发布于 2017-05-10 09:30:42
在load函数中,解除绑定事件,单击body。清除处理程序unbind
$(function () {
$('body').unbind('click')
$('body').on('click', '.close-modal', function (e) {
if (strText.length > 0 {
if ($('.modal-container').length > 1) {
$('.modal-container').last().remove();
$('.modal-window').last().remove();
}
}
e.preventDefault();
});
});https://stackoverflow.com/questions/43882176
复制相似问题