我对js中的if语句有疑问。我做了一个声明,但它似乎不起作用。我想通过单击“按钮 1”来检查这些语句。该脚本是在我计算总数之前检查是否有任何运输费用。有人可以告诉我如何解决我的问题吗?
这是我的脚本:
<SCRIPT TYPE="text/javascript">
function berekeningen()
{
if (document.getElementById("DropdownMenu1").value = "Eeklo" && document.getElementById("Order_Subtotal").firstChild.data >= 20)
{
document.getElementById("Transportation_Cost").value="0.00";
}
else
{
document.getElementById("Transportation_Cost").value="3.00";
}
if (document.getElementById("DropdownMenu1").value = "Adegem" && document.getElementById("Order_Subtotal").firstChild.data >= 25)
{
document.getElementById("Transportation_Cost").value="0.00";
}
else
{
document.getElementById("Transportation_Cost").value="3.00";
}
if (document.getElementById("DropdownMenu1").value = "Kaprijke" && document.getElementById("Order_Subtotal").firstChild.data >= 25)
{
document.getElementById("Transportation_Cost").value="0.00";
}
else
{
document.getElementById("Transportation_Cost").value="3.00";
}
if (document.getElementById("DropdownMenu1").value = "Lembeke" && document.getElementById("Order_Subtotal").firstChild.data >= 25)
{
document.getElementById("Transportation_Cost").value="0.00";
}
else
{
document.getElementById("Transportation_Cost").value="3.00";
}
if (document.getElementById("DropdownMenu1").value = "Oosteeklo" && document.getElementById("Order_Subtotal").firstChild.data >= 25)
{
document.getElementById("Transportation_Cost").value="0.00";
}
else
{
document.getElementById("Transportation_Cost").value="3.00";
}
if (document.getElementById("DropdownMenu1").value = "Sint-Laureins" && document.getElementById("Order_Subtotal").firstChild.data >= 25)
{
document.getElementById("Transportation_Cost").value="0.00";
}
else
{
document.getElementById("Transportation_Cost").value="3.00";
}
if (document.getElementById("DropdownMenu1").value = "Ursel" && document.getElementById("Order_Subtotal").firstChild.data >= 25)
{
document.getElementById("Transportation_Cost").value="0.00";
}
else
{
document.getElementById("Transportation_Cost").value="3.00";
}
if (document.getElementById("DropdownMenu1").value = "Waarschoot" && document.getElementById("Order_Subtotal").firstChild.data >= 25)
{
document.getElementById("Transportation_Cost").value="0.00";
}
else
{
document.getElementById("Transportation_Cost").value="3.00";
}
if (document.getElementById("DropdownMenu1").value = "Zomergem" && document.getElementById("Order_Subtotal").firstChild.data >= 25)
{
document.getElementById("Transportation_Cost").value="0.00";
}
else
{
document.getElementById("Transportation_Cost").value="3.00";
}
if (document.getElementById("DropdownMenu1").value = "Knesselare")
{
document.getElementById("Transportation_Cost").value="5.00";
}
if (document.getElementById("DropdownMenu1").value = "Lovendegem")
{
document.getElementById("Transportation_Cost").value="5.00";
}
if (document.getElementById("DropdownMenu1").value = "Bassevelde")
{
document.getElementById("Transportation_Cost").value="5.00";
}
if (document.getElementById("DropdownMenu1").value = "Maldegem")
{
document.getElementById("Transportation_Cost").value="5.00";
}
}
</SCRIPT>
编辑:我用变量稍微改变了脚本,但它不起作用
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.js"></script>
<SCRIPT TYPE="text/javascript">
function berekeningen()
{
var plaats = document.getElementById("plaats").value;
var kosten = document.getElementById("kosten").value;
var subtotaal = document.getElementById("Bestelling_subtotaal").firstChild.data
var class_1_plaatsen = new Array("Eeklo");
var class_2_plaatsen = new Array("Adegem", "Kaprijke", "Lembeke", "Oosteeklo",
"Sint-Laureins", "Ursel", "Waarschoot", "Zomergem");
var class_3_plaatsen = new Array("Knesselare", "Lovendegem", "Bassevelde", "Maldegem");
if ($.inArray(plaats, class_1_plaatsen) >= 0) {
// Berekening voor plaatsen in prijscategorie 1 hieronder.
}
else if ($.inArray(plaats, class_2_plaatsen) >= 0) {
// Berekening voor plaatsen in prijscategorie 2 hieronder.
}
else {
// Berekening voor overige plaatsen hieronder.
}
}
</SCRIPT>
我不想这样做:
当 var plaats = class_1_plaatsen 且 subtoal < 15 时,发出警报(我们使用 vanaf 最低 15 欧元)。但如果小计介于 15 和 20 之间,则 kosten = 3。但如果小计 >= 20,则 kosten = 0。
当 var plaats = class_2_plaatsen 且 subtoal < 20 时,发出警报(我们使用 vanaf 最低 20 欧元)。但如果小计介于 20 和 25 之间,则 kosten = 3。但如果小计 >= 25,则 kosten = 0。
当 var plaats = class_3_plaatsen 且 subtoal < 20 时,发出警报(我们使用 vanaf 最低 20 欧元)。但如果小计 >= 20,则 kosten = 5。
戴斯腾