Setting the select
element's value to an empty string is the correct way to do it. However, that only updates the root select
element. The custom chosen
element has no idea that the root select
has been updated.
In order to notify chosen
that the select
has been modified, you have to trigger chosen:updated
:
$('#autoship_option').val('').trigger('chosen:updated');
or, if you're not sure that the first option is an empty string, use this:
$('#autoship_option')
.find('option:first-child').prop('selected', true)
.end().trigger('chosen:updated');
Read the documentation here (find the section titled Updating Chosen Dynamically).
P.S. Older versions of Chosen use a slightly different event:
$('#autoship_option').val('').trigger('liszt:updated');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…