[英]listbox with 3 values
Is it possible to assign value like this in a listbox? 是否可以在列表框中分配这样的值?
$("#transfernumber").append("" + couponnumber + "");
I am having 3 values such as id
, amount
and couponnumber
. 我有3个值,例如id
, amount
和couponnumber
。 I have to display the coupon number and I want to retrieve amount when selecting list box. 选择列表框时,我必须显示优惠券编号,并且我想取回金额。
You need to append the element as option to listbox. 您需要将元素作为选项附加到列表框。 like this: 像这样:
$('#transfernumber').append('<option value="amount">coupon_num</option>');
you can achieve this one by using html5 custom attributes
. 您可以使用html5 custom attributes
来实现这一目标。 data-amount
$("#transfernumber").append("<option value='" + couponid + "' data-amount='"+amount+"'>" + couponnumber + "</option>");
To retrieve this one by using .data()
通过使用.data()
来检索此
var amount = $("#transfernumber").data( "amount");
you can use .attr for this 您可以为此使用.attr
<script>
$(document).ready(function()
{
$( "option" ).attr('id','test');
$( "option" ).attr('amount',5757);
$( "option" ).attr('coupon','testcoupon');
});
</script>
<select>
<option>hiiii</option>
</select>
You can add as follows 您可以添加如下
$('#transfernumber').append(
$('<option/>', {
value: '1',
'data-amount': '100',
html: 'couponnumber'
})
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.