[英]Does jQuery Live work on Safari?
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? 我刚刚在一小时前问过这个问题但是关于IE8,我被告知JQuery Live处理程序不支持“更改”所以我切换到“点击”,这解决了我的问题,现在我发现Safari不起作用点击一些奇怪的原因,任何人都知道为什么?
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? 还是有更优雅的东西?
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()
if ($.browser.msie
但是如何用上面这个做,上面也是$(document).ready(function()
尝试这个:
$('select.htt, select.hst').live($.browser.msie?'click':'change', function() { ....
It seems you are running into a combination of issues here: 您似乎遇到了以下问题的组合:
change
event does not bubble in IE , while the click
event does change
事件不会在IE中冒泡 ,而click
事件会发生 click
event does not fire/buuble on <select>
/ <option>
elements in Safari , while the change
event does click
事件不会在Safari中的<select>
/ <option>
元素上触发/ buuble ,而change
事件会触发/ buuble 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. 每当菜单添加到DOM时,我只需要让代码重新绑定更改处理程序,或者甚至可以在服务器脚本生成的情况下向select添加onchange属性。
Reading through the buglist ( http://bugs.jquery.com/ticket/5677 ) adding following CSS to the element is a solution as well : 阅读bug列表( http://bugs.jquery.com/ticket/5677 ),将以下CSS添加到元素中也是一个解决方案:
<style>
element {
cursor : pointer;
}
</style>
Works on iphone4 with safari 适用于带有safari的iphone4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.