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
. 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
. data-amount
$("#transfernumber").append("<option value='" + couponid + "' data-amount='"+amount+"'>" + couponnumber + "</option>");
To retrieve this one by using .data()
var amount = $("#transfernumber").data( "amount");
you can use .attr for this
<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'
})
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.