- 爱易网页
-
JavaSript
- 关于innerHTML 的有关问题
日期:2014-05-16 浏览次数:20361 次
关于innerHTML 的问题
以下代码运行,可以生成一个table,,然后点击table的onclick事件却 ,不能得到 dd 值,, dd值已经在onMouseOver里面赋值了,,但IE提示 语法错误,,
那应该怎样写才对啊?
<head>
<script language= "javascript ">
var dd = " ";
function test(){
objDragItem = document.createElement( "DIV ");
objDragItem.id = "ttt ";
var menuItemContainer=document.getElementById( "t1 ");
menuItemContainer.insertBefore(objDragItem);
var P_199 = "P_199 ";
objDragItem.innerHTML = " <table bgColor= '#CCCCCC ' width= '100 ' onMouseOver= 'dd=kk ' onclick= 't(); '> <tr> <td> dfsdfs </td> <tr> </table> ";
}
function t(){
alert(dd);
}
</script>
</HEAD>
<BODY bgcolor= "#FFFFFF " text= "#000000 " leftmargin= "0 " topmargin= "0 ">
<DIV id= "t1 "> </DIV>
<a href= "javascript:void(0) " onClick= "test(); "> 生成 table </a>
</BODY>
------解决方案--------------------
<html>
<head>
<script language= "javascript ">
var dd = " ";
function test(){
objDragItem = document.createElement( "DIV ");
objDragItem.id = "ttt ";
var menuItemContainer=document.getElementById( "t1 ");
menuItemContainer.insertBefore(objDragItem);
var P_199 = "P_199 ";
objDragItem.innerHTML = ' <table bgColor= "#CCCCCC " width= "100 " onMouseOver= "dd=\ 'kk\ ' " onclick= "t(); "> <tr> <td> dfsdfs </td> <tr> </table> ';
}
function t(){
alert(dd);
}
</script>
</HEAD>
<BODY bgcolor= "#FFFFFF " text= "#000000 " leftmargin= "0 " topmargin= "0 ">
<DIV id= "t1 "> </DIV>
<a href= "javascript:void(0) " onClick= "test(); "> 生成 table </a>
</BODY>
------解决方案--------------------
kk未定义