HTML SELECT - Trigger JavaScript ONCHANGE event ev

2019-01-06 10:23发布

I have the following markup:

<select onchange="jsFunction()">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
</select>

When a user pulls down the combobox and selects the same option that was previously selected (or doesn't change the selection at all), JavaScript doesn't regard it as an onchange event. So, the jsFunction() is not called. But I want the jsFunction() called even in this case. How can I achieve this?

8条回答
再贱就再见
2楼-- · 2019-01-06 11:20

Try this. Just add an empty option. This will solve your problem.

<select onchange="jsFunction()">
    <option></option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
</select>​
查看更多
疯言疯语
3楼-- · 2019-01-06 11:23

This works:

<select name="type" onmousedown="this.value='';" onchange="alert('Changed.');">
  <option value='1'>One</option>
  <option value='2'>Two</option>
  <option value='3'>Three</option>
  <option value='4'>Four</option>
  <option value='5'>Five</option>
  <option value='6'>Six</option>
  <option value='7'>Seven</option>
  <option value='8'>Eight</option>
  <option value='9'>Nine</option>
  <option value='10'>Ten</option> 
</select>
查看更多
登录 后发表回答