select重复选择同一项,还能够触发onchange事件

<select id="type" name="type" title="智能设计参数设计类型">
    <option value="请选择" disabled>请选择</option>
    <option value="01">格局和功能</option>
    <option value="02">风格</option>
    <option value="03">颜色</option>
    <option value="04">预算</option>
</select>
//下拉列表改变事件
$("#type").change(function () {
    //要执行的代码操做
}).mousedown(function () { //当按下鼠标按钮的时候
    this.sindex = $(this)[0].selectedIndex;  
    $(this)[0].selectedIndex = 0; //把当前选中的值得索引赋给下拉选中的索引
}).mouseout(function () { //当鼠标移开的时候
    if ($(this)[0].selectedIndex === 0) { //若是为0,就是根本没有选
        $(this)[0].selectedIndex = this.sindex; //就把下拉选中的索引改变成以前选中的值得索引,就默认选择的是以前选中的 
    }
});

当你重复点击同一项的时候,你会发现根本不会执行onchange方法.你们能够依照上面的方法,就能够实现重复点击的时候也可以实现onchange方法了,有关select事件的一些用法函数,请看个人另外一篇博文https://my.oschina.net/u/2306318/blog/1551225函数

相关文章
相关标签/搜索