鍍金池/ 問(wèn)答/HTML/ js中,如何把這三個(gè)綁定寫(xiě)成一個(gè)?

js中,如何把這三個(gè)綁定寫(xiě)成一個(gè)?

$('#hetong_fu1').bind('input propertychange',function(){
    debugger;
    $('#deposit1').val(car_deposit());
});
$('#hetong_ya1').bind('input propertychange',function(){
    debugger;
    $('#deposit1').val(car_deposit());
});
$('.floor_rent').bind('input propertychange',function(){
    debugger;
    $('#deposit1').val(car_deposit());
});
回答
編輯回答
幼梔

你這樣試試

$('#hetong_fu1,#hetong_ya1,.floor_rent').bind('input propertychange',function(){

debugger;
$('#deposit1').val(car_deposit());

});

2018年5月14日 10:21
編輯回答
糖果果

先為這些元素添加一樣的classname,比如hetong,然后jq有隱形迭代,下面這么做就可以了。

$('.hetong').bind('input propertychange',function(){
    debugger;
    $('#deposit1').val(car_deposit());
});
2017年12月28日 10:34
編輯回答
生性

將上面的綁定元素改成變量,比如:

function bindEvent(element){
    $(element).bind("input propertychange", function(){
        ...
    });
}
調(diào)用方式
bindEvent("#hetong_ya1");
或者:
var arr = ["#hetong_fu1", "#hetong_ya1", ".floor_rent"];
arr.forEach(function(item, index, array){
    bindEvent(item);
});
2017年8月12日 06:06
編輯回答
墨沫
$('#hetong_fu1, #hetong_ya1, .floor_rent').bind('input propertychange',function(){
    debugger;
    $('#deposit1').val(car_deposit());
});
2017年12月3日 15:58