带有DOM插入的简单javascript错误
我写了这段简单的代码来在列表中插入一个单词,但由于某种原因,在Chrome中,我对DOM的更改会出现大约1/10秒,然后消失。Firefox中没有发生任何事情带有DOM插入的简单javascript错误,javascript,html,dom,getelementbyid,Javascript,Html,Dom,Getelementbyid,我写了这段简单的代码来在列表中插入一个单词,但由于某种原因,在Chrome中,我对DOM的更改会出现大约1/10秒,然后消失。Firefox中没有发生任何事情 <html> <head> <script> window.onload = init; function init(){ var button = document.getElementById("submit"); button.onclick = changeDiv; } fun
<html>
<head>
<script>
window.onload = init;
function init(){
var button = document.getElementById("submit");
button.onclick = changeDiv;
}
function changeDiv(){
var textInput = document.getElementById("textInput");
var userInput = textInput.value;
alert("adding " + userInput);
var li = document.createElement("li");
li.innerHTML = userInput;
var ul = document.getElementById("ul");
ul.appendChild(li);
}
</script>
</head>
<body>
<form id="form">
<input id="textInput" type="text" placeholder="input text here">
<input id="submit" type="submit">
</form>
<ul id="ul">
</ul>
</body>
</html>
window.onload=init;
函数init(){
var按钮=document.getElementById(“提交”);
button.onclick=changeDiv;
}
函数changeDiv(){
var textInput=document.getElementById(“textInput”);
var userInput=textInput.value;
警报(“添加”+用户输入);
var li=document.createElement(“li”);
li.innerHTML=用户输入;
var ul=document.getElementById(“ul”);
ul.儿童(li);
}
您没有取消提交按钮操作,因此页面正在提交表单
function changeDiv (e) {
if (!e)
e = window.event;
//IE9 & Other Browsers
if (e.stopPropagation) {
e.stopPropagation();
}
//IE8 and Lower
else {
e.cancelBubble = true;
}
...
您没有取消提交按钮操作,因此页面正在提交表单
function changeDiv (e) {
if (!e)
e = window.event;
//IE9 & Other Browsers
if (e.stopPropagation) {
e.stopPropagation();
}
//IE8 and Lower
else {
e.cancelBubble = true;
}
...
您没有取消提交按钮操作,因此页面正在提交表单
function changeDiv (e) {
if (!e)
e = window.event;
//IE9 & Other Browsers
if (e.stopPropagation) {
e.stopPropagation();
}
//IE8 and Lower
else {
e.cancelBubble = true;
}
...
您没有取消提交按钮操作,因此页面正在提交表单
function changeDiv (e) {
if (!e)
e = window.event;
//IE9 & Other Browsers
if (e.stopPropagation) {
e.stopPropagation();
}
//IE8 and Lower
else {
e.cancelBubble = true;
}
...
表单已提交,页面将重新加载、更改
<input id="submit" type="submit">
到
表单已提交,页面将重新加载、更改
<input id="submit" type="submit">
到
表单已提交,页面将重新加载、更改
<input id="submit" type="submit">
到
表单已提交,页面将重新加载、更改
<input id="submit" type="submit">
到