[英]How to set the dropdownlist value?
I am using this technique: is there a way to hold the values? 我正在使用这种技术: 是否可以保存值? - lost in postback
-在回发中丢失
After it does the postback, how do I set which item is selected? 执行回发后,如何设置选择哪个项目?
$(document).ready(function() {
if (document.getElementById("txtHidData").value != "")
$("#country").val(document.getElementById("txtHidData").value);
//or
//$("#country")[0].selectedIndex = document.getElementById("txtHidData").value;
Does not work either way, any help? 两种方法都不起作用,有帮助吗? Thanks.
谢谢。
EDIT: 编辑:
$("#country").change(function() {
debugger
var _selected = $("#country option:selected").val();
document.getElementById("txtHidData").value = "";
document.getElementById("txtHidData").value = _selected;
// $("#txtHidData").value = _selected;
.... ....
I don't know exactly what your markup looks like, but here's a shot: 我不知道您的标记到底是什么样子,但是这里有一个镜头:
$(document).ready(function () {
var val = $("#txtHidData").val();
if (val !== "") {
$("#country > option[value=" + val + "]").attr("selected", "selected");
}
...
});
Try not to mix jQuery and the native DOM functions if jQuery provides equivalent functions. 如果jQuery提供了等效功能,请尽量不要将jQuery和本机DOM函数混合使用。 Doing so defeats the purpose of using jQuery.
这样做违反了使用jQuery的目的。
Edit: had some incorrect open/close quotes. 编辑:有一些不正确的打开/关闭引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.