所以我有两个下拉列表,其中包含用HTML编程的值。一旦用户点击一个下拉列表的选择,我需要将值传递给名为searchVector的javascript函数。这是我到目前为止的代码。如果这是重新发布,请在高级中道歉。
<li>
<select name="Industry" id="indy" onchange="accountindustry(value)">
<option value="">Filter By Industry</option>
<script language="javascript">drawIndustryList();</script>
</select>
</li>
<li>
<select name="ServiceSegment" id="sersec" onchange="accountservicesegment(value)">
<option value="">Filter By Service Segment</option>
<script language="javascript">drawServiceList();</script>
</select>
</li>
答案 0 :(得分:0)
不使用其他库,您可以将this
传递给回调:
<select name="Industry" id="indy" onchange="accountindustry(this)">
然后将值访问为:
function accountindustry(select_object) {
var value = select_object.options[select_object.selectedIndex].value;
}
答案 1 :(得分:0)
如果我理解你的问题,你会尝试做类似的事情:
<select name="filter" id="filter" onchange="changeFilter(this)">
<option value=""></option>
<option value="Industry">Filter By Industry</option>
<option value="ServiceSegment">Filter By Service Segment</option>
</select>
<script type="text/javascript">
function changeFilter(el) {
searchVector(el.value);
}
</script>
答案 2 :(得分:0)
引用当前元素,使用特殊变量this
:
<select name="Industry" id="indy" onchange="accountindustry(this.value)">
value
本身不是变量,它是元素的属性。