Javascript AppendChild自动刷新表单
我有一个小代码,可以将列表项从一个列表移动到另一个列表。该代码在IE8中运行,但在IE10或chrome中不起作用。onclick事件之后,列表项从列表的左侧移动到右侧,但随后,页面似乎会自动刷新 如果我删除了标记,那么代码可以工作,但我需要标记。当onclick事件发生时,如何停止javascript以不刷新页面。我尝试了其他帖子中提到的几个解决方案,但没有一个奏效。如果你能在这方面帮助我,我将不胜感激。 我不想发布所有代码。因此,我创建了一个示例页面Javascript AppendChild自动刷新表单,javascript,html,Javascript,Html,我有一个小代码,可以将列表项从一个列表移动到另一个列表。该代码在IE8中运行,但在IE10或chrome中不起作用。onclick事件之后,列表项从列表的左侧移动到右侧,但随后,页面似乎会自动刷新 如果我删除了标记,那么代码可以工作,但我需要标记。当onclick事件发生时,如何停止javascript以不刷新页面。我尝试了其他帖子中提到的几个解决方案,但没有一个奏效。如果你能在这方面帮助我,我将不胜感激。 我不想发布所有代码。因此,我创建了一个示例页面 <!DOCTYPE html PU
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Test</title>
<script>
function AppendList()
{
//event.preventDefault(); I also tried AppendList(event)
var node = document.getElementById("batchReportLists0").lastChild;
document.getElementById("batchReportLists1").appendChild(node);
alert("Added Last Item");
//return false;
//window.onbeforeunload = function(){
//return "Refresh";
}
</script>
</head>
<body>
<form name="batchReportForm" enctype="multipart/form-data">
<table style="text-align: left; width: 100%;" border="1"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td>
<select multiple="multiple" size="15" name="T1"
class="bodyText" id="batchReportLists0">
<option>Msg1</option>
<option>Msg2</option>
</select>
</td>
<td> <button onclick="AppendList();">
>>> </button>
</td>
<td>
<select multiple="multiple" size="15" name="T2"
class="bodyText" id="batchReportLists1">
<option>Msg3</option>
<option>Msg4</option>
</select>
</td>
</tr>
</tbody>
</table>
<br>
</form>
</body>
</html>
试验
函数AppendList()
{
//event.preventDefault();我还尝试了AppendList(事件)
var node=document.getElementById(“batchReportLists0”).lastChild;
document.getElementById(“batchReportLists1”).appendChild(节点);
警报(“添加的最后一项”);
//返回false;
//window.onbeforeunload=函数(){
//返回“刷新”;
}
Msg1
Msg2
Msg3
Msg4
让它成为
<button type="button">Button</button>
按钮
默认情况下,
充当提交。要添加/删除什么标记?