Firefox的JavaScript问题设置变量 [英] Firefox javascript problem setting variable
问题描述
我已经做了一个小小的JavaScript脚本,设置一个值(在这里命名股票),我想在下拉列表中使最大值。如果它大于6,它将是最大值。
这里是代码:
< script type =text / javascript>
函数selecteazaElement(id,stock)
{
document.addtobasket.idOfSelectedItem.value = id;
var number23 = document.addtobasket.number;
number23.options.length = 0;
if(stock> = 6)
stock = 6;
for(i = 1; i <= stock; i ++)
{
// alert('id:'+ id +'; stock:'+ stock);
number23.options [number.options.length] = new Option(i,i);
}
//window.status=\"my status;
}
< / script>
我使用这种形式的代码:
< form =addtobasketname =addtobasketmethod =POSTaction =<?= Route :: url('Add to Basket' sale_id'=> $ sale-> id));?>>
< input type =hiddenname =idOfSelectedItemid =idOfSelectedItemvalue = - 1>
< option value = 0>选择产品数量< / option> < /选择>
< button type =submitname =submitonclick =valbutton(addtobasket);> Adauga in cos< / button>< br />
< / fieldset>
< / form>因此,在用户选择一个产品后,形成一个列表,他也可以选择一个(产品)数量,
我的问题是:
它在Chrome和Opera中完美工作,但不会在Firefox的下拉列表中显示数字。我不知道为什么呢?
谢谢!
解决方案在Firefox中导致这个问题:
number23.options [number.options.length] = new Option(i,i) ;
更改为:
number23.options [number23.options.length] = new Option(i,i);
,它就会起作用。
您的原始代码: http://jsfiddle.net/CS6uv/1/ (在Firefox中不起作用)
更正后的代码 http://jsfiddle.net/CS6uv/2/ (适用于Firefox)
i have made a little javascript script that sets a value (named here stock), which i want to make maximum in a drop down list. it will be the maximum value if it is greater that 6.
Here is the code:
<script type="text/javascript">
function selecteazaElement(id,stock)
{
document.addtobasket.idOfSelectedItem.value=id;
var number23=document.addtobasket.number;
number23.options.length=0;
if (stock>=6)
stock=6;
for (i=1;i<=stock;i++)
{
//alert ('id: '+id+'; stock: '+stock);
number23.options[number.options.length]=new Option(i, i);
}
//window.status="my status";
}
</script>
i use this code in this form:
<form id="addtobasket" name="addtobasket" method="POST" action="<?= Route::url('Add to Basket', array('sale_id' => $sale->id)); ?>">
<input type="hidden" name="idOfSelectedItem" id="idOfSelectedItem" value="-1">
<select name="number" id="number">
<option value=0>Choose the number of products</option> </select>
<button type="submit" name = "submit" onclick="valbutton(addtobasket");>Adauga in cos</button><br />
</fieldset>
</form>
So after the user chooses a product,form a list he can also choose a number(of products)
my problem is:
It works perfectly in chrome and opera, but doesn't display the numbers in the drop down list in Firefox. i wonder why is that?
Thank you!
解决方案 This line is causing the problem in Firefox:
number23.options[number.options.length]=new Option(i, i);
Change it to:
number23.options[number23.options.length]=new Option(i, i);
and it will work.
Your original code: http://jsfiddle.net/CS6uv/1/ (doesn't work in Firefox)
Corrected code: http://jsfiddle.net/CS6uv/2/ (works in Firefox)
这篇关于Firefox的JavaScript问题设置变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!