在下拉Javascript中更改所选内容
我有以下下拉列表:在下拉Javascript中更改所选内容,javascript,jquery,html,Javascript,Jquery,Html,我有以下下拉列表: <select size="1" name="foo" id="foo" style="cursor: pointer;"> <option value="bla1;" class=" nAll" selected="1">Requests</option> <option value="bla2;" class=" nAll">Requests Rate</option> </select&g
<select size="1" name="foo" id="foo" style="cursor: pointer;">
<option value="bla1;" class=" nAll" selected="1">Requests</option>
<option value="bla2;" class=" nAll">Requests Rate</option>
</select>
基本上,我在URL中发送了一个参数,我希望在重新加载页面时正确设置下拉列表
出于某种原因,这就是我运行代码时发生的情况:
<select size="1" name="foo" id="foo" style="cursor: pointer;">
<option value="bla1;" class=" nAll" selected="selected">Requests</option>
<option value="bla2;" class=" nAll" selected="selected">Requests Rate</option>
</select>
请求
请求率
我希望实现的目标是:
<select size="1" name="foo" id="foo" style="cursor: pointer;">
<option value="bla1;" class=" nAll" selected="0">Requests</option>
<option value="bla2;" class=" nAll" selected="1">Requests Rate</option>
</select>
请求
请求率
传递给getUrlParameter
方法的值应该是字符串。但它已作为url
变量值传递
var getUrlParameter=函数getUrlParameter(sParam){
var sPageURL=decodeURIComponent(window.location.search.substring(1)),
sURLVariables=sPageURL.split(“&”),
sParameterName,
我
对于(i=0;i
请求
请求率
我最后使用了“porp”阿曲丁胺,如下所示:
要查找当前选定的选项,请执行以下操作:
("#foo").prop("selectedIndex")
要设置下拉列表,请执行以下操作:
("#foo").prop("selectedIndex",optionIndex)
参数的名称是什么?是“url”吗?必须将选项设置在数字的选定位置,对吗?我从url中获取一个数字,该数字应该是选定的选项。参数名称是什么?是这样的吗?是的,那么值=1
("#foo").prop("selectedIndex",optionIndex)