javascript - 我的功能不断刷新

标签 javascript html arrays forms submit

我有一个小问题,为什么我的页面在显示数据后不断刷新。我使用这段代码,

<input type="submit" value="Submit" align="center" Onclick="hitung()" class="myButton" >

但是如果我将 type="submit" 更改为 type="button"

这是我的函数hitung()

function hitung(){

var e = (document.getElementById("ifin").value);
var a = (document.getElementById("Furniture").value);
var panjang =(document.getElementById("ipanjang").value);
var ht = 0.0;
var hf = 0.0;
var total = 0.0;

if (e == "hpl") {

				hf = 0.0;
			}
else if(e == "cat")
			{
				hf = 0.5;
}
else {
				hf = 0.0;
}
if (a == "kitchen"){
				ht = 1.7;	
}
else if (a == "meja"){
				ht = 2.3;	
}
else {
				ht = 0.0;
}
total = panjang*ht+hf;
document.getElementById("ototal").innerHTML ="Harga Total : Rp."+total.toFixed(2)+"0.000,00"+"<br>Sudah termasuk ongkir";
}

提前致谢

最佳答案

将 hithung() 定义更改为:

   function hitung(e)
{
e.preventDefault();

// Body of function.

}

关于javascript - 我的功能不断刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46845412/

相关文章:

javascript - 表单文本字段变量在 Javascript 中显示未定义

Javascript Truthy/Falsy 操作

javascript - jquery:在div中加载html页面

asp.net-mvc-3 - 使用纯 HTML 和 MVC 3 上传大文件

python - python 中用于 nd 数组的逻辑索引

c - 从文件中获取多个矩阵并将其存储在整数指针中

javascript - 在 angularjs 中创建一个可编辑的下拉菜单

javascript - 使 div 上的颜色根据您单击的位置而变化

javascript - 如何获取 FilteringSelect 选项并使用 dojo 添加新选项

javascript - 如何使用JS提交表单