下拉值相同时如何调用onchange事件 [英] How to call onchange event when dropdown values are same

查看:129
本文介绍了下拉值相同时如何调用onchange事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jquery选择的插件,并且工作正常.我已经在我的模块之一中使用了此插件.我的下拉值是这样的:

I am using Jquery chosen plugin and it's working fine. I have used this plugin in my one of the module. My dropdown values are something like that:

<select id="itemcode" onchange="get_data()">
   <option value="1">ITEM001</option>
   <option value="2">ITEM002</option>
   <option value="1">ITEM001</option>
   <option value="3">ITEM003</option>
</select>

一切正常.但是问题在于,当用户选择第一个选项然后尝试更改第三个选项时,onchange事件不会触发,因为两个选项的值都相同.如果值相同或不同,有什么方法每次都可以调用onchange事件吗?

It's working fine. But problem is that when user select first option and then try to change third option onchange event does not fire because both options values are same. Is there any way to call onchange event every time if values are same or differ ?

选项值是项的唯一键,因此在下拉列表中会重复.下拉值是重复的,我们允许在其他模块中使用相同的项目

Options values is a unique key of item so it's repeated in dropdown. Dropdown value is duplicate we have allowed to use same item in others module

推荐答案

我看到了您的实现,并且在代码笔中运行良好,这里的链接无需更改任何内容

I saw your implementation and it is working fine in code pen here is the link no need to change anything

<select id="itemcode" onchange="get_data()">
<option value="1">ITEM001</option>
<option value="2">ITEM002</option>
<option value="1">ITEM001</option>
<option value="3">ITEM003</option>
</select>

var get_data =function(){
alert("saas")
}

http://codepen.io/vkvicky-vasudev/pen/dXXVzN

这篇关于下拉值相同时如何调用onchange事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆