我希望 javascript 执行多次,但它只执行一次。下面的代码工作得很好,但是在单击两个按钮后,我必须刷新页面才能使其再次工作。请帮我解决这个问题。只想多次执行它,但不刷新页面。
HTML:
<body>
<h1 class="head" id="h" onclick="change()">TEST PAGE</h1>
<form name="myform">
<input name="horizontal" type="button" class="button1" value="Swap Horizontal" id="SH1" onclick="swaphorizontal()">
</form>
<form name="myform1">
<input name="vertical" type="button" class="button2" value="Swap Vertical" id="SV1" onclick="swapvertical()">
</form>
<h2 class="mybox"></h2>
<h2 class="line1"></h2>
<h2 class="line2"></h2>
<h2 class="voidbutton1"></h2>
<h2 class="voidbutton2"></h2>
</body>
JS:
<script>
function swapvertical() {
document.getElementById("SV1").style.top = "210px";
document.getElementById("SH1").style.top = "414px";
}
function swaphorizontal() {
document.getElementById("SV1").style.left = "386px";
document.getElementById("SH1").style.left = "178px";
}
</script>