关于 document.createElement()的用法
<html><head><title>test</title><metahttp-equiv="Content-Type"content="text/html;chars...
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">
function co(){
var aa = document.getElementById("xx");
alert(aa);
var e = document.createElement("input");
e.type = "button";
e.value = "这是测试加载的小例子";
var object = aa.appendChild(e);
}
</script>
</head>
<body>
<div id="xx" onclick="co();">adsfsadf</div>
</body>
</html>
----------------------------------------------------------------------------------
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">
function co(){
var aa = document.getElementById("xx");
alert(aa);
var e = document.createElement("input");
e.type = "button";
e.value = "这是测试加载的小例子";
var object = aa.appendChild(e);
}
</script>
</head>
<body>
<div id="xx" onclick="co();">adsfsadf</div>
</body>
</html>
为什么只有是函数的那个才能实现,主要是 var aa = document.getElementById("xx"); 这个获取不到值为什么 急等!!! 展开
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">
function co(){
var aa = document.getElementById("xx");
alert(aa);
var e = document.createElement("input");
e.type = "button";
e.value = "这是测试加载的小例子";
var object = aa.appendChild(e);
}
</script>
</head>
<body>
<div id="xx" onclick="co();">adsfsadf</div>
</body>
</html>
----------------------------------------------------------------------------------
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">
function co(){
var aa = document.getElementById("xx");
alert(aa);
var e = document.createElement("input");
e.type = "button";
e.value = "这是测试加载的小例子";
var object = aa.appendChild(e);
}
</script>
</head>
<body>
<div id="xx" onclick="co();">adsfsadf</div>
</body>
</html>
为什么只有是函数的那个才能实现,主要是 var aa = document.getElementById("xx"); 这个获取不到值为什么 急等!!! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询