考虑下面的代码:<TR>标签未订阅事件
<!DOCTYPE html> <!-- HTML5 -->
<html>
<head>
<meta http-equiv="Expires" content="Fri, Jan 01 1900 00:00:00 GMT">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="content-language" content="en">
<title>Untitled</title>
<script type='text/javascript'>
function createTableRow() {
var tr = document.createElement("tr");
var strWork = "<tr onmouseover='this.style.cursor=\"pointer\";'";
strWork += " onmouseout='this.style.cursor=\"auto\";'";
strWork += " onclick='ShowClick(this);'";
strWork += " id='TestCell'><td>Test!</td></tr>";
alert(strWork);
tr.outerHTML = strWork;
return tr;
}
function BuildTable() {
var table = document.createElement("table");
table.appendChild(createTableRow());
return table;
}
function ShowClick(obj) {
alert(obj.id);
}
</script>
</head>
<body onload='alert(BuildTable().outerHTML);'>
</body>
</html>
第一个“警告”对话框中显示的标签,我想形成它,但是,在“的onload =警报”行返回结果“ <表> < tr> </tr> </table>“。
我在做什么错?为什么这些事件不与TR标签绑定?
另外,我想补充一点,我最初分配使用JavaScript的事件,即:
tr.onclick = function() { ShowClick(this); };
但有完全相同的结果...
我真的不明白这一点,我无法在任何地方找到任何有关该问题的讨论......任何帮助将不胜感激!
请学习在现代浏览器中使用'console.log()'。 – 2012-08-20 01:12:30
@ JaredFarrish--请学会宽容使用的浏览器。 – RobG 2012-08-20 01:52:03
@RobG - 哈哈,有趣的东西。除非你认真,在这种情况下,你呢? – 2012-08-20 01:53:35