[jquery問題]attr更改id無法再觸發問題(已解決)
[code]<style>#div1{
background:blue;
}
#div2{
background:red;
}
</style>
<script type="text/javascript">
$(function(){
$("input").click(function () {
$(".test").attr({id:"div2"});
});
$("#div1").click(function () {
alert("hello div1");
});
$("#div2").click(function () {
alert("hello div2");
});
});
</script>
</head>
<body>
<div class='test' id="div1">hello world!</div>
<input type='button' value='click me!'/>[/code]我測試過alert,確定id有改為div2
修改完的id無法觸動,不知道是寫錯了,還是jquery本來就不支援這種方式呢?
另外只有css可以正常切換[code]<script>
$("tt").click(function () {
alert($(".test").attr("id"));
});
</script>
<input type='button' id='tt'>[/code]
[[i] 本帖最後由 xxoxxoxxoxx 於 2009-11-10 15:33 編輯 [/i]] 我覺得這個問題跟你之前遇到的一個似乎蠻像的:
[url]http://jsgears.com/thread-293-1-1.html[/url]
你在 bind div2 event 時, div2 並不存在,可以試試看改用 live() 再次感謝大大指導,小弟怎麼沒想不到:L
謝謝:lol
頁:
[1]