雖然function中有更改id但是還是會執行$(#ooo).toggle();
且ID會變成nufined;
- <html>
- <head>
- <style type='text/css'>
- div { background-color: #dddddd; width: 60px; margin: 5px; }
- </style>
- <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.js'></script>
- <script type='text/javascript'>
- $(function() {
- $("#xxx").live("click", function () { alert("YA!"); });
- $("input:button").attr("id", "ooo");
- $("#ooo").toggle(
- function () {
- alert($("input#ooo").attr("id"));
- $("body").append("<div id=\"xxx\">XXX</span>");
- },
- function () {
- alert($("input#ooo").attr("id"));
- $("body").append("<div id=\"xxx\">XXX2</span>");
- },
- function () {
- alert($("input#ooo").attr("id"));
- $("#ooo").unbind(); //終止toggle()事件
- $(this).attr("id", "xxxx"); //更改id內容
- alert($("input").attr("id"));
- $("body").append("<div id=\"xxx\">XXX3</span>");
- }
- );
- });
- </script>
- </head><body>
- <input type="button" value="TEST" />
- </body>
- </html>
$("input").attr("disabled", true); //停用按鈕參數設定