为什么我的javascript代码没有激活该功能?

时间:2016-12-11 19:58:19

标签: javascript select dropdown

<script>
function doWork(search) {
alert(search);
if (search=="blue") {window.open("db-loader.php", "_blank",
  "location=yes,height=570,width=575,scrollbars=yes,status=yes")};
if (search=="list") {form.submit()};
}
</script>


<form action="retspro-find.php" method="GET">
  <select name="search" id="search" onchange="doWork(search)">
  <option value="access">Access</option>
  <option value="yellow">Yellow</option>
  <option value="blue">Blue</option>
  <option value="list">List</option>
  <option value="demo">Demo</option>
  </select>
</form>

我没有在功能的警报中看到任何事情..当我从两个位置删除单词搜索时它将点亮警报但不激活任何例程....只是试图得到这个词搜索以选择所选择的选项并将其发送到该功能,例如点击时蓝色应该在搜索中显示蓝色并转到该功能并激活弹出窗口... 感谢

2 个答案:

答案 0 :(得分:0)

变化:

<select name="search" id="search" onchange="doWork(search)">

<select name="search" id="search" onchange="doWork(this.value)">

JSFiddle:https://jsfiddle.net/dudu84/tLhnedsL/

答案 1 :(得分:0)

只需更改

onchange="doWork(search)"

onchange="doWork(this.value)"