使用javascript/jQuery在文本输入中生成随机数
我试图在文本字段中生成一个随机数。不幸的是,这里没有ID选项,所以我使用类作为标识符。我尝试了很多方法,但似乎都无法成功 用于输入的HTML:使用javascript/jQuery在文本输入中生成随机数,javascript,jquery,Javascript,Jquery,我试图在文本字段中生成一个随机数。不幸的是,这里没有ID选项,所以我使用类作为标识符。我尝试了很多方法,但似乎都无法成功 用于输入的HTML: <div class="productAttributeRow productAttributeConfigurableEntryNumbersOnlyText"> <div class="productAttributeLabel"> <label> <span
<div class="productAttributeRow productAttributeConfigurableEntryNumbersOnlyText">
<div class="productAttributeLabel">
<label>
<span class="name">
Hidden:
</span>
</label>
</div>
<div class="productAttributeValue">
<input type="text" class="Field validation" value="" size="5" />
</div>
</div>
在上述场景中,#购买此
是一个按钮:
<a id="BuyThis" type="button" class="btn btn-small btn-warning" href="#product-options" data-toggle="modal">
另一次尝试:
function randomNumber(m, n) {
m = parseInt(m);
n = parseInt(n);
randomnumber = Math.floor(Math.random() * (n - m + 1)) + m;
('.productAttributeConfigurableEntryNumbersOnlyText.productAttributeValue input[type="text"]').value = randomnumber;
});
尝试了各种其他功能和组合,但均无效 类为
productAttributeValue
的div位于productAttributeConfigurableEntryNumbersOnlyText
内,因此选择时应在它们之间添加空格:
$(function(){
var randomnumber=Math.floor(Math.random()*11)
$('.productAttributeConfigurableEntryNumbersOnlyText .productAttributeValue input[type="text"]').val( randomnumber );
});
$('.productAttributeConfigurableEntryNumbersOnlyText .productAttributeValue')
有效:类为
productAttributeValue
的div位于productAttributeConfigurableEntryNumbersOnlyText
内,因此选择时应在它们之间添加空格:
$(function(){
var randomnumber=Math.floor(Math.random()*11)
$('.productAttributeConfigurableEntryNumbersOnlyText .productAttributeValue input[type="text"]').val( randomnumber );
});
$('.productAttributeConfigurableEntryNumbersOnlyText .productAttributeValue')
是否有效:
正在选择一个元素,该元素同时具有.productAttributeConfigurableEntryNumberOnlyText
和.productAttributeValue
您要选择一个元素,该元素具有.productAttributeValue
,它是.productAttributeConfigurableEntryNumberOnlyText
的子元素
为此,请在它们之间添加一个空格:
$(function(){
var randomnumber=Math.floor(Math.random()*11)
$('.productAttributeConfigurableEntryNumbersOnlyText .productAttributeValue input[type="text"]').val( randomnumber );
});
$('.productAttributeConfigurableEntryNumbersOnlyText .productAttributeValue')
要插入随机值,请使用:
var randomnumber=Math.floor(Math.random()*11)
$('.productAttributeConfigurableEntryNumbersOnlyText .productAttributeValue input[type="text"]').val( randomnumber );
正在选择一个元素,该元素同时具有.productAttributeConfigurableEntryNumberOnlyText
和.productAttributeValue
您要选择一个元素,该元素具有.productAttributeValue
,它是.productAttributeConfigurableEntryNumberOnlyText
的子元素
为此,请在它们之间添加一个空格:
$(function(){
var randomnumber=Math.floor(Math.random()*11)
$('.productAttributeConfigurableEntryNumbersOnlyText .productAttributeValue input[type="text"]').val( randomnumber );
});
$('.productAttributeConfigurableEntryNumbersOnlyText .productAttributeValue')
要插入随机值,请使用:
var randomnumber=Math.floor(Math.random()*11)
$('.productAttributeConfigurableEntryNumbersOnlyText .productAttributeValue input[type="text"]').val( randomnumber );
试试这个。。。
HTML
试试这个。。。
HTML
试试看你能提供你问题的演示吗?你能提供你问题的演示吗?哈哈哈…我看了大概半打,但同时做了一百万件事情,却总是忘了做。哼!谢谢,非常感谢。我在这方面的工作时间比我应该做的要长得多,看到它起作用,我感到非常欣慰。谢谢~SusanHa哈哈…我大概看了半打,但同时做了一百万件事情,却一直忘了做。哼!谢谢,非常感谢。我在这方面的工作时间比我应该做的要长得多,看到它起作用,我感到非常欣慰。谢谢~苏珊