简体   繁体   中英

change the default selected option in a select via jquery

I have a select list where one option is selected by default when the page loads.

When a different option is selected, the html I view in Firebug does not change.

I have a button that makes copies of this element, and would like the copies to have the same selected value as this one, but they all have the default value selected.

How can I make the copies have the same selected values as the original?

When you clone the element you should be able to set the cloned select's value to that of the original. Eg,

var $select = $('#my-select'),
    $clone = $select.clone().val($select.val());
// I don't know where you really want the clone, just an example...
$clone.insertAfter($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