I a使用claviska jquery选择框https://github.com/claviska/jquery-selectBox
以下是代码
<div class="section">
<label>Location</label>
<div>
<select class="small selectBox" id="GeoLocation"style="display: none; padding: 6px;">
<option value="1">London</option>
<option value="2">Madrid</option>
<option value="3">Paris</option>
<option value="4">New York</option>
</select>
</div>
</div>当列表是静态的时,我没有问题,它会适当地显示在列表框中。我的问题是,如何使用从服务器端获得的信息在选择框中设置默认值。
默认情况下,我会将“London”作为默认值。
我在JS var id=2 (它是马德里)中有支持,我如何设置selectBox将‘马德里’显示为默认值?
如何在JQuery中构建列表?
默认情况下,在生成的HTML之后(选择伦敦)
<div>
<select class="small selectBox" id="GeoLocation" style="display: none; padding: 6px;">
<option value="1">London</option>
<option value="2">Madrid</option>
<option value="3">Paris</option>
<option value="4">New York</option>
</select>
<a class="selectBox small selectBox-dropdown" style="width: 62px; display: inline-block;" title="" tabindex="0">
<span class="selectBox-label" style="width: 35px;">London</span>
<span class="selectBox-arrow"></span></a>
</div>发布于 2012-11-15 15:39:41
你可以试试这种方式。
var id=2;
// Select the option with the corresponding value..
// capture the text or html inside it
var city = $('#GeoLocation option[value="'+ id+ '"]').text();
// Set the text to the text in select
$('.selectBox-label').text(city);https://stackoverflow.com/questions/13393213
复制相似问题