js 动态添加属性不能显示(在兼容模式下不显示,正常的显示
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/...
<!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" lang="zh-CN">
<head>
<title>图片垂直居中</title>
<script type="text/javascript" language="javascript">
function test(id) {
var div1 = document.getElementById(id);
var div2 = document.createElement("div");
div2.setAttribute("style","border:1px solid red;width:30px;height:20px;margin:3px;");
div2.setAttribute("onclick","javascript:alert('提示消息!');");
div1.insertBefore(div2, div1.firstChild);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<input type="button" onclick="test('mainDiv')" value="添加" />
<div id="mainDiv" style="border:1px solid red;width:100px; height:50px;">
</div>
</body>
</html> 展开
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>图片垂直居中</title>
<script type="text/javascript" language="javascript">
function test(id) {
var div1 = document.getElementById(id);
var div2 = document.createElement("div");
div2.setAttribute("style","border:1px solid red;width:30px;height:20px;margin:3px;");
div2.setAttribute("onclick","javascript:alert('提示消息!');");
div1.insertBefore(div2, div1.firstChild);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<input type="button" onclick="test('mainDiv')" value="添加" />
<div id="mainDiv" style="border:1px solid red;width:100px; height:50px;">
</div>
</body>
</html> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询