[英]How to override a JavaScript function from a common file?
我在通用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文件称为previous,因此没有调用我的change ...实现此目的的任何选项。
StrText是我的json_enoded字符串。
在您的加载函数中,取消绑定事件,单击主体。 清除处理程序解除绑定
$(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();
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.