简体   繁体   中英

jQuery Chosen plugin - select option manually

I've been trying to select some options manually in the Chosen plugin.

Why i need something like that?

My concept is :Let's say a user wants to put some tags to a video,when he inserts the video to the database the tags will be saved in a database too. When he wants to edit this video i have to query these tags from the database and show them to the user so he can edit/delete/add new.

My question:

Is there any way to put these tags in an array and then put them as an already selection?

Just add the selected property when you get the existing tags from the database. Let us say a video is tagged with a and b , so when you show the select list it would look like this:

<select id="assets" data-placeholder="Choose assets" class="chzn-select" multiple style="width:350px;">
    <option value="a" selected>a</option>
    <option value="b" selected>b</option>
    <option value="c">c</option>
    <option value="d">d</option>
    <option value="e">e</option>
    <option value="f">f</option>
    <option value="g">g</option>
</select>

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