例如我複製從api.jquery.comjQuery的.change()不觸發選擇 - 從api.jquery.com
$('.target').change(function() {
alert('Handler for .change() called.');
});
這個例子中我也嘗試:
$('#target').change(function() {
alert('Handler for .change() called.');
});
我複製它放到我的.js文件中,它包含在我的html中。我還有一個jQuery函數在那裏(開始$(窗口).load(函數(){...」
其他功能正在起作用。但上面的簡單的功能是沒有的。
的形式看起來像這樣的:
<form>
<select id="target" class="target">
<option name="pp" value="6">6</option>
<option name="pp" value="12">12</option>
</select>
</form>
我只想用ID,但我添加的類只是用於測試但無論是作品
爲什麼沒有這個簡單的函數工作我需要做別的連接。?更改事件的功能?我是jQuery的新手,但我知道在javas中cript我必須讓表單的onchange事件調用函數才能發生。
編輯:好的,這裏是我包括的.js文件中的一切。正如你所看到的,只有一個其他功能。它干擾了嗎? 另外,我只在頁面上有一個表格,你在上面看到。我將會改變每頁顯示的結果數(6或12)。
$(window).load(function() {
$("img.gall_img").each(function() { // iterate through all img of class gall_img
var imgWidth = $(this).width(); // "$(this)" to access jQuery width() func
var divWidth = $(this).closest('div').width();
//alert(imgWidth + " and " + divWidth); // for debugging
if(imgWidth > divWidth) {
var position = Math.round(-1 * ((imgWidth/2) - (divWidth/2))); //
position = position + "px"; // make position format "123px".
$(this).css("left", position); // "$(this)" to access jQuery css() func
}
});
});
$("#target").change(function() {
alert('Handler for .change() called.');
});
處理程序綁定在DOMReady後面嗎? –
你應該上傳完整的代碼 –
你使用什麼瀏覽器版本? –