我有點問題,爲什麼我的頁面在數據顯示後不停地刷新。我用這個代碼,我的功能不斷刷新
<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") {
\t \t \t \t hf = 0.0;
\t \t \t }
else if(e == "cat")
\t \t \t {
\t \t \t \t hf = 0.5;
}
else {
\t \t \t \t hf = 0.0;
}
if (a == "kitchen"){
\t \t \t \t ht = 1.7; \t
}
else if (a == "meja"){
\t \t \t \t ht = 2.3; \t
}
else {
\t \t \t \t ht = 0.0;
}
total = panjang*ht+hf;
document.getElementById("ototal").innerHTML ="Harga Total : Rp."+total.toFixed(2)+"0.000,00"+"<br>Sudah termasuk ongkir";
}
感謝
由於「提交」類型的輸入將提交表單(如果它是在表單中的行爲),所以基本上,如果您單擊該提交按鈕,它將轉到指定的表單操作。 –
這個問題是不完整的,請提供整個頁面代碼或內容hitung() –
我試過使用'event.preventDefault()',但那使我的功能不工作 –