是否可以监听点击并更改一个代码?
$(document).on("click", "button.options_buy",function(event) {
// same code
}
$(document).on("change", "select.options_buy",function(event) {
// same code
}
我试试这个
$(document).on("click change", "button.options_buy,select.options_buy",function(event) { }
它有效,但我只想对“button.options_buy”进行“点击”,对“select.options_buy”进行“更改”
这可能吗?
最佳答案
最好的方法是拥有两个事件处理程序,但只有一个从每个事件处理程序调用的公共(public)函数:
$(document).on("click", "button.options_buy",function(event) {
commonFunction();
})
$(document).on("change", "select.options_buy",function(event) {
commonFunction();
})
function commonFunction(){
//common function code
}
关于javascript - Jquery结合点击和更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37902108/