日期:2014-05-16 浏览次数:20401 次
function test() { var myDocument = document; var htmlElement = myDocument.documentElement var bodyElement = htmlElement.getElementsByTagName("body")[0]; var items = bodyElement.getElementsByTagName("a"); for ( var i = 0 ; i < items.length; i ++ ) { var itemAttributes = items[i].getAttribute("id"); if ( itemAttributes.substr(0,3) == "aaa" ) { var parentTD = items[i].parentNode ; if ( parentTD != null) { parentTD.setAttribute("height","500"); alert(parentTD.getAttribute("onmousedown")); parentTD.setAttribute("onmousedown","function anonymous() { ShowDiv(); }"); alert(parentTD.getAttribute("onmousedown")); } } } } function ShowDiv() { if ( window.event.button == "2") { alert("I'm a Event....."); } }
<body> <table border = "1"> <tr> <td> <a id = "aaa" href="#">bbbb</a> <input type="button" value="test" onClick="test();"/> </td> </tr> </table> </body>