最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Does jQuery Live work on Safari? - Stack Overflow

programmeradmin5浏览0评论

I have just asked this question an hour ago but with regards to IE8 and I was told that the JQuery Live handlers does not support "change" so I switched over to "click", this solved my problem and now I find Safari does not work with click for some strange reason, anyone know why?

So I was thinking can I just have both?

$('select.htt, select.hst').live('click', function() {
    var channels = parseInt($('#fancy_div select.hst').val(), 10) * parseInt($('#fancy_div select.htt').val(), 10);         
    $('#fancy_div span.yellow2').html(channels + ' Channels');
});

And change(which works on safari)

$('select.htt, select.hst').live('change', function() {
    var channels = parseInt($('#fancy_div select.hst').val(), 10) * parseInt($('#fancy_div select.htt').val(), 10);         
    $('#fancy_div span.yellow2').html(channels + ' Channels');
});

Or is there something more elegant?

EDIT

Maybe I can do a conditional. if ($.browser.msie But how would I do this with the above, the above is also in a $(document).ready(function()

I have just asked this question an hour ago but with regards to IE8 and I was told that the JQuery Live handlers does not support "change" so I switched over to "click", this solved my problem and now I find Safari does not work with click for some strange reason, anyone know why?

So I was thinking can I just have both?

$('select.htt, select.hst').live('click', function() {
    var channels = parseInt($('#fancy_div select.hst').val(), 10) * parseInt($('#fancy_div select.htt').val(), 10);         
    $('#fancy_div span.yellow2').html(channels + ' Channels');
});

And change(which works on safari)

$('select.htt, select.hst').live('change', function() {
    var channels = parseInt($('#fancy_div select.hst').val(), 10) * parseInt($('#fancy_div select.htt').val(), 10);         
    $('#fancy_div span.yellow2').html(channels + ' Channels');
});

Or is there something more elegant?

EDIT

Maybe I can do a conditional. if ($.browser.msie But how would I do this with the above, the above is also in a $(document).ready(function()

Share Improve this question edited May 23, 2017 at 12:02 CommunityBot 11 silver badge asked Oct 26, 2009 at 14:28 AbsAbs 58k103 gold badges282 silver badges418 bronze badges 3
  • 1 I haven't had any problems with "click" event bubbling in Safari. – Pointy Commented Oct 26, 2009 at 14:30
  • "click" in the live handler? What safari version do you use and on what OS. Mine is on windows and its a version 4. – Abs Commented Oct 26, 2009 at 14:38
  • 1 Safari 4 on Windows. Click events bubble just fine. What have you done in attempts to debug the problem? Have you tried setting up your own version of what "live()" does in order to see whether the events are making to your container element(s)? – Pointy Commented Oct 26, 2009 at 14:45
Add a ment  | 

4 Answers 4

Reset to default 4

Try this:

$('select.htt, select.hst').live($.browser.msie?'click':'change', function() { ....

It seems you are running into a bination of issues here:

  1. The change event does not bubble in IE, while the click event does
  2. The click event does not fire/buuble on <select>/<option> elements in Safari, while the change event does

I'm not sure of the best way forward for your situation though.

The change event shouldn't bubble in ANY browser.

I would just have your code re-bind the change handler whenever the menu is added to the DOM, or perhaps even add an onchange attribute to the select if it's generated by a server script.

Reading through the buglist (http://bugs.jquery./ticket/5677) adding following CSS to the element is a solution as well :

<style>
  element {
      cursor : pointer;
  }
</style>

Works on iphone4 with safari

Reference

发布评论

评论列表(0)

  1. 暂无评论