我有這個代碼可以顯示在HTML的div標籤下拉。在這裏,我已經設置了一個函數「hello()」來通過jquery下拉菜單,但問題在於它沒有調用該函數。如何更改使用jQuery的onChange事件的調用函數
<body>
<div id="content"></div>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$("#content").append('<select id="sel" onchange="fly()"><option value="1">Choose Me</option></select>');
$("#sel").attr("onchange", "hello()");
alert($("#sel").attr("onchange"));
function hello() {
alert("Hello");
}
function fly() {
alert("Go to fly");
}
</script>
</body>
這將執行hello函數,並將返回值(undefined)傳遞給change()。 – Jivings 2012-03-29 15:51:36
@Jivings更新回答 – Curt 2012-03-29 15:52:41