Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript HTML下拉列表将字典值设置为在jquery中选择的值_Javascript_Jquery_Html Select - Fatal编程技术网

Javascript HTML下拉列表将字典值设置为在jquery中选择的值

Javascript HTML下拉列表将字典值设置为在jquery中选择的值,javascript,jquery,html-select,Javascript,Jquery,Html Select,我有一个HTML下拉列表。下拉列表的数据源是字典。选定的值键将存储在隐藏字段中。在页面重新加载时,我想将字典中的值设置为下拉列表中的选定值。字典键将存储在隐藏字段中 var IxCustomer = $(_this.IxCustomerHiddenFieldId).val(); $(_this.CustomerSelectId).find("option[value=" + IxCustomer + "]").attr("selected", true); 我如何修改这个 这应该可以做到:

我有一个HTML下拉列表。下拉列表的数据源是字典。选定的值键将存储在隐藏字段中。在页面重新加载时,我想将字典中的值设置为下拉列表中的选定值。字典键将存储在隐藏字段中

var IxCustomer = $(_this.IxCustomerHiddenFieldId).val();

$(_this.CustomerSelectId).find("option[value=" + IxCustomer  + "]").attr("selected", true);
我如何修改这个

这应该可以做到:

$(_this.CustomerSelectId).val(IxCustomer);

设置
元素的值可以选择相应的选项。

您可以将代码放入JSFIDLE吗?