我写的这段js代码为什么能在DW中正确显示,在浏览器中不能出结果
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content...
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
var n=1;
function show(){
var ul=document.getElementById('wuxu');
var li=document.createElement('li');
n++;
li.innerHTML="<a href='*'>"+"Item"+" "+n+"</a>";
ul.appendChild(li);
}
</script>
</head>
<body>
<ul id=wuxu>
<li>Item 1</li>
</ul>
<form id="form1" name="form1" method="post" action="">
<input type="submit" name="add" onclick="show()" id="add" value="ADD item" />
</form>
</body>
</html>
我 展开
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
var n=1;
function show(){
var ul=document.getElementById('wuxu');
var li=document.createElement('li');
n++;
li.innerHTML="<a href='*'>"+"Item"+" "+n+"</a>";
ul.appendChild(li);
}
</script>
</head>
<body>
<ul id=wuxu>
<li>Item 1</li>
</ul>
<form id="form1" name="form1" method="post" action="">
<input type="submit" name="add" onclick="show()" id="add" value="ADD item" />
</form>
</body>
</html>
我 展开
1个回答
展开全部
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
var n=1;
function show(){
var ul=document.getElementById('wuxu');
var li=document.createElement('li');
n++;
li.innerHTML="<a href='*'>"+"Item"+" "+n+"</a>";
ul.appendChild(li);
}
</script>
</head>
<body>
<ul id=wuxu>
<li>Item 1</li>
</ul>
<input type="submit" name="add" onclick="show()" id="add" value="ADD item" />
</body>
</html>
代码应该这样写,你加上<form id="form1" name="form1" method="post" action="">
之后每次单击<input>后先生成一个li,随后表单被提交页面刷新一次,所以li就没了
追问
666
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询