我有两个下拉列表,我从数据库中绑定了数据。
<tr>
<td>
<label for="ddlCountry">
Country</label>
</td>
<td>
<select id="ddlCountry" name="ddlCountry">
</select>
</td>
</tr>
<tr>
<td>
<label for="ddlCurency">
Currency</label>
</td>
<td>
<select id="ddlCurrency" name="ddlCurrency">
</select>
</td>
</tr>我已经使用Jquery将数据绑定到这些数据。
对于ddlCurrency:
var $html1 = '';
$html1 += '<option value="">---Select Currency---</option>';
if ($currencyList != null || $currencyList != '') {
$.each($currencyList, function (index, item) {
$html1 += '<option value=' + item.Currency + '>' + item.Currency + '</option>';
});
}
$('#ddlCurrency').append($html1);对于ddlCountry:
var $html = '';
$html += '<option value="">---Select Country---</option>';
if ($countryList != null || $countryList != '') {
var $i = 0;
$.each($countryList, function (index, item) {
$html += '<option value=' + $i + '>' + item.Country + '</option>';
$i++;
});
}
$('#ddlCountry').append($html);现在的问题是,当我编程地尝试选择下拉列表项目时,就会出现问题。数据绑定没有问题。当我将参数传递给在我的例子中来自网格(不是asp.net网格视图)的值时,只有ddlCountry显示带有传递参数的项,但是ddlCurrency显示--选择货币--这是我在ddlCurrency中的第一项,这意味着它没有选择任何内容。
下面是通过传递参数来选择下拉项的代码。
$('select[id=ddlCountry] option:contains(' + argus[5] + ')').attr('selected', true);
$("#ddlCurrency option[value=" + argus[6] + "]").attr('selected', 'selected');只有第一个选项选择下拉列表项和所需的项,第二个选项只选择,两个arg都有值。
当我这么做的时候:
$("#ddlCurrency option[value=" + 'USD' + "]").attr('selected', 'selected');它在下拉列表中选择项目。
发布于 2014-02-02 20:19:22
将argus[6]放在单引号中(Attribute Equals选择器):
$("#ddlCurrency option[value='" + argus[6] + "']")https://stackoverflow.com/questions/21515600
复制相似问题