无法使用jQuery选择下拉列表的值

时间:2014-08-28 06:08:49

标签: javascript jquery xml

我正在尝试使用jQuery在“select”控件中设置值。据观察,有时它正确选择值,有时它不选择值。

我有一个xml文档,下面是代码拉取xml值并将其设置为下拉列表(html select) 这是我的jQuery Bock。

var select = '#' + formname + ' select[binding="true"]'; //here select those dropdown whose binding property is true.
$(select).each(function (i) {
    var bindName = $(this).attr("DataMember");
    if (bindName != '') {
        $xmlNode = $xml.find(bindName);
        if ($xmlNode != null) {
            var value = $xmlNode.text();
            if (value == "0")
                value = '';
            $(this).val(value); //here actual value is set as per xml value
        }
        else
            $(this).val('');
        $(this).trigger("change");
        $(this).trigger("chosen:updated");
    }
});

有些时候,这段代码无法正常工作。 任何人都可以告诉我这段代码有什么问题。

0 个答案:

没有答案