我有一個函數,如果調用,將更新另一個對象,如果它存在。事情是,當頁面被創建時,id是未知的。動態查找jQuery元素如果存在
因此,舉例來說,我的繼承人代碼:
$('.slides').on("slidestop", function() {
$this = $(this);
$.ajax({
url: "action.php?event=ITEM "+$this.attr("data-itemID") + " " + this.value+"&itemID="+$this.attr("data-itemID"),
type:'POST',
success: function(result){
//update brightness slider if it exists
$("#sl" + $this.attr('data-itemID')).val(15);
$("#sl" + $this.attr('data-itemID')).slider("refresh");
},
});
});
HTML:
<input class='dimmerSlider' type='range' id='3' value='4' min='0' max='15' step='1' data-highlight='true' data-itemID='3'/>
錯誤:
Uncaught TypeError: $(...).slider is not a function
使用合適的報價,'$(「#$ this.attr( 「data-itemID」)「)。val(15);'=>'$(」#$ this.attr('data-itemID')「)。val(15);' – Tushar