2013-03-05 64 views
-3

如何將表值放入彈出框中?相反,選擇的表值時,輸出「不確定」彈出框值

<script> 
    function conf() { 
    var x, res, y; 
    res = document.getElementById('t').onclick 
    if(document.formxml.num1.value >= 2) { 
     var r = confirm("Reserve for " + document.formxml.num1.value + " persons in "+document.formxml.res. + "?"); 
    } else if(document.formxml.num1.value == 1) { 
     var r = confirm("Reserve for " + document.formxml.num1.value + " person in " + document.formxml.res. + "?"); 
    } else if(document.formxml.num1.value < 0) { 
     var r = confirm("You cannot input a negative number!"); 
    } 

    if(r == true) { 
     x = ""; 
     location.href = 'res3.html' 
    } else if(r == false) { 
     x = ""; 
    } 
    } 
</script> 

</head> 
<body> 

    <style type="text/css"> 
    .txt {width:50px;} 
    </style> 

    <form action="" method="get" name="formxml"> 
    For how many persons? 
    <input type="text" name="num1" value="" class="txt" id="num1" maxlength="2"> 
    <input type="button" value="Table 1" id="t" name="res" onclick="conf();"> 
    <input type="button" value="Table 3" id="t" name="res" onclick="conf();"> 
    </form> 

我不知道下一步是什麼後var r=confirm("Reserve for "+document.formxml.num1.value+" person in "+document.formxml.res.+"?");

+3

至少花時間縮進你的代碼。 – PeeHaa 2013-03-05 12:09:56

回答

2

你讓每個if塊中重新聲明的變量r,有效地引起從confirm()返回的值永遠不會到達你閱讀它的地方。

試圖聲明r一勞永逸與其他變量一起:

var x, res, y, r; 

拖放你在哪裏賦值r線的var關鍵字。