jquery-addclass然后用作选择器



我需要了解如何在添加类后使用我添加的类作为jquery中的选择器。因此,本质上,当我用ID#ds_I更改日期范围时,它会向按钮添加一个类,当按下该按钮时,我会弹出一个窗口。到目前为止,我的代码如下。

$("#ds_i").on('change', function(){  
$( "#save-button" ).addClass( "sweet-date-pop" );
});
$(".sweet-date-pop").click(function(e,params) {
var localParams = params || {};
if (!localParams.send) {
e.preventDefault();
}
swal({
title: "This job is in progress.",
text: "Are you sure you would like to change the dates?",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-warning",
confirmButtonText: "Yes,change dates!",
closeOnConfirm: false,
closeOnCancel: false
}, function(isConfirm){
if (isConfirm) {
$(e.currentTarget).trigger(e.type, {'send': true});
} else {
swal("Cancelled", "Nothing Was Changed", "error");
}
});
});  

从主体委派

$("body").on('click','.sweet-date-pop',function(e,params) {
//rest of the code
})

相关内容

最新更新