选项的单击事件在 IE 中不起作用 [英] click event for option doesn't work in IE

查看:16
本文介绍了选项的单击事件在 IE 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多选标签,我需要编写它的选项的onclick函数,因为我需要获取最后点击选项的值,但是当我写了以下内容时

I have a multiple select tag, and I need to write the function onclick of it's options, because I need to get the value of last clicked option, but when I wrote the following

$("#multiple_select option").click(function()
{
     var val = $(this).val();
     alert(val);
});

它在 IE 中不起作用.

it doesn't work in IE.

有什么问题?

我需要完全点击事件,因为我已经写了一个函数 onclick 事件(演示 here),我需要修复最后更改元素的值,如果没有点击事件,这是不可能的(我认为)

I need exactly click event, because I wrote a function onclick event already(demo here), and I need to fix last changed element's value, which is impossible to make without click event(I think)

推荐答案

不要在选项上绑定它

$("#multiple_select").click(function(){
     alert("works");
});

<小时>

接受的答案:


accepted answer:

$(document).ready(function()
{
    var options = $("#supply_cities_select :selected");
    var lastOption;
    $("#supply_cities_select").click(function()
        {
            lastOption = $(this).find(':selected').not(options);
            options = $(this).find(':selected');
        })
});

这篇关于选项的单击事件在 IE 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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