简体   繁体   中英

Chosen get selected option custom attribute

I'm filling a JQuery Chosen with values, and I'm setting a custom attribute to get it later when an option is selected, but I can't find a nice way to do it.

My code is the following:

$( "#ddlChosen" ).chosen();

for (var i = 0; i < entities.length; i++) {
    $( "#ddlChosen" ).append($('<option>', { value: entities[i].id, 
            text: entities[i].name, uniqueID: entities[i].uniqueID }));
}

And what I want is to get the uniqueID property. Is there a way to accomplish this?

Any help will be appreciated :)

try this

var options = $( "#ddlChosen option:selected" );

for (var i = 0; i < options.length; i++) {
    var property = $(options[i]).attr('uniqueID');

    alert(property);
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM