0

我对html一无所知,尤其是javascript..但是我们有这个关于如何调用位于<head></head>html标记处的javascript函数的活动?

如果有多个功能怎么办?可以一键同时调用吗?还是我应该创建另一个函数并将所有函数放在那里?

这就是我们活动的全部内容......在一个javascript按钮中,当点击时,它必须计算所有交易?我有 5 个函数,其中一个由按钮标签调用,而另外 4 个在该函数内部。我真的不知道该怎么办......但是当我点击按钮时,什么都不会发生。顺便说一句,这是一个预订表格,所以当点击按钮时,它必须计算所有输入并显示价格等的确认页面/警报。多谢你们!

这是我的表单代码:

<form name="reserve" action="" id="reserve" method="post">

<fieldset>
<legend>Contact Information</legend>
<label for="name">Name: </label>
<input type="text" name="firstname" value="firstname" 
  onfocus="if (this.value==this.defaultValue)this.value='';"
  onblur="if(this.value=='')this.value=this.defaultValue;"/>
<input type="text" name="lastname" value="lastname"
  onfocus="if(this.value==this.defaultValue)this.value='';" 
  onblur="if(this.value=='')this.value=this.defaultValue;"/>
<br>

<label for="address">Address: </label>
<textarea name="address" cols="30" rows="3"></textarea>

<br>

<label for="city">City: </label>
<input type="text" name="city">

<label for="country">Country: </label>
<select name="country">
<option value=""></option>
<option value="PH">Philippines</option>
<option value="TH">Thailand</option>
<option value="VN">Vietnam</option>
<option value="MY">Malaysia</option>
<option value="ID">Indonesia</option>
<option value="SG">Singapore</option>
</select>

<br>

<label for="email">Email: </label>
<input type="email" name="email">

<label for="phone">Phone: </label>
<input type="tel" name="phone">
</fieldset>
<hr>

<fieldset>
<legend>Accomodation Request</legend>
<label for="checkin">Check-in: </label>
<input type="date" name="checkin">

<label for="checkout">Check-out: </label>
<input type="date" name="checkout">

<br>

<label for="roomtype">Room type: </label> <br>
<input type="checkbox" id="s" name="roomtype" value="superior">Superior  |||||
<label for="sguest">No.of guests: </label>
<input type="text" id="supg" name="sguest" size="3"> <br>

<input type="checkbox" id="d" name="roomtype" value=deluxe">Deluxe |||||||
<label for="dguest">No.of guests: </label>
<input type="text" id="delg" name="dguest" size="3"> <br> 

<input type="checkbox" id="p" name="roomtype" value="Premier">Premier |||||
<label for="pguest">No.of guests: </label>
<input type="text" id="premg" name="pguest" size="3"> <br>
</fieldset>

<br>
<hr>

<label for="adinfo">Additional Information:</label>
<textarea name="adinfo" cols="40" rows="10"></textarea>
<br><br>
<hr>
<input type="button" name="submit" onclick="formSubmit()" 
  class="submit" value="Reserve">



</form>

这是javascript代码:

function superiorroom(){
    var roomprice=0;
    var theForm = document.forms["reserve"]
    var s = theForm.elements["s"]
    var supg = theForm.elements["supg"]
    var t=0;

    If (s.checked==true)
    {
        roomprice=5400;
        squantity=parseInt(squantity.value);
        t=parseInt(t);
        t= (roomprice*squantity)*supg;
    }
    return t;
}

function deluxeroom(){
    var roomprice=0;
    var theForm = document.forms["reserve"]
    var d = theForm.elements["d"]
    var delg = theForm.elements["delg"]
    var u=0;

    If (d.checked==true)
    {
        roomprice=7200;
        dquantity=parseInt(dquantity.value);
        u=parseInt(u);
        u= (roomprice*dquantity)*delg;
    }
    return u;
}

function premiumroom(){
    var roomprice=0;
    var theForm = document.forms["reserve"]
    var p = theForm.elements["p"]
    var premg = theForm.elements["premg"]
    var v=0;

    If (p.checked==true)
    {
        roomprice=9800;
        pquantity=parseInt(pquantity.value);
        v=parseInt(v);
        v= (roomprice*pquantity)*premg;
    }
    return u;
}


</script>

我希望你们能帮助我伙计们!

4

2 回答 2

0

嗨,我已经更改了您的代码,请检查一下

<input type="button" name="submit" onclick="return formSubmit()" class="submit" value="Reserve">
于 2013-10-07T06:20:02.507 回答
0

我像这样更改了您的代码:Try This Button

<input type="button" id="submit" name="submit" onclick="return formSubmit()" class="submit" value="Reserve">

Scripts

<script>
$("#submit").click(function () {
       if ( document.getElementById("s").checked =checked)
           superiorroom();
        else if(document.getElementById("d").checked =checked)
            deluxeroom();
        else if(document.getElementById("p").checked =checked)
           premiumroom();

    });
</script>

<script>
function superiorroom(){
    var roomprice=0;
    var theForm = document.forms["reserve"]
    var s = theForm.elements["s"]
    var supg = theForm.elements["supg"]
    var t=0;

    If (s.checked==true)
    {
        roomprice=5400;
        squantity=parseInt(squantity.value);
        t=parseInt(t);
        t= (roomprice*squantity)*supg;
    }
    return t;
}

function deluxeroom(){
    var roomprice=0;
    var theForm = document.forms["reserve"]
    var d = theForm.elements["d"]
    var delg = theForm.elements["delg"]
    var u=0;

    If (d.checked==true)
    {
        roomprice=7200;
        dquantity=parseInt(dquantity.value);
        u=parseInt(u);
        u= (roomprice*dquantity)*delg;
    }
    return u;
}

function premiumroom(){
    var roomprice=0;
    var theForm = document.forms["reserve"]
    var p = theForm.elements["p"]
    var premg = theForm.elements["premg"]
    var v=0;

    If (p.checked==true)
    {
        roomprice=9800;
        pquantity=parseInt(pquantity.value);
        v=parseInt(v);
        v= (roomprice*pquantity)*premg;
    }
    return u;
}
</script>
于 2013-10-07T06:49:31.700 回答