日期:2014-05-16 浏览次数:20529 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>hasAttribute BUG in all browser?</title> </head> <body> <table> <tr><td id="a">111</td></tr> <tr><td id="b">222</td></tr> </table> <input id="aa" type="button" value="改变aTD" /> <script type="text/javascript" language="javascript"> document.getElementById('aa').onclick = function(){ document.getElementById('a').innerHTML = '1222'; if(document.getElementById('a').innerHTML != '111'){ document.getElementById('b').innerHTML = 'TD发生了改变'; } }; </script> </body> </html>
------解决方案--------------------
<table> <tr> <td id="first">111</td> </tr> <tr> <td>222</td> </tr> <tr> <td>333</td> </tr> <tr> <td>444</td> </tr> <tr> <td>555</td> </tr> </table> <input type=button value="增加" onclick=func() /> <script type="text/javascript"> function func() { var first = document.getElementById("first"); first.innerHTML = parseInt(first.innerHTML)+111; var next = first.parentNode.nextSibling; while(next != null) { if(next.tagName =="TR") { var td = next.getElementsByTagName("td")[0]; td.innerHTML = parseInt(td.innerHTML)+111; } next = next.nextSibling } } </script>