我有一個PHP生成的頁面中的選擇列表,我在顯示的頁面中多次加載動態內容。這些選項中的每一條都應該起到鏈接的作用;因此我將select元素上的'click'處理程序與篩選器連接起來,以選擇其選項元素。首先,這個起點是我使用的HTML:jQuery的.on功能與動態內容不工作ie9
<select name="suggestions" id="suggestions" size="3">';
</select>';
後來我填寫一些選項如下:
<option value="NextPage.php?id=1">Doe, John</option>
所附的javascript如下:
$(document).ready(function() {
...
$("#suggestions").on('click', 'option', selectItem);
});
// receiving the list of options
function receiveList(data) {
$('#suggestions').html(data);
$('#suggestions').css('display', 'inline');
}
// The click handler for the options
function selectItem(e) {
var txt = this.value;
alert('Selected ' + txt);
window.open(txt); // or window.location.href = txt;
}
這個JavaScript在Firefox和Opera中完美工作;在IE9中,當單擊選擇器中的一行時,所選行將變爲藍色,但不執行任何操作,並且不會彈出警告(即,不會執行selectItem)。
我使用jQuery-1.8.2.min.js,並在頁面的第一行是「!DOCTYPE HTML」
任何建議如何解決這個問題?
的點擊事件的''不火的IE瀏覽器,使用select代替 –