繁体   English   中英

jQuery Click事件在Firefox和Safari浏览器中不起作用

[英]JQuery Click event is not working in Firefox and Safari Browsers

我需要在图像上放置注释标记,当用户单击每个注释时,需要为图像显示相应的注释消息。

它在Chrome浏览器(IOS和Android)和台式机的chrome浏览器中均能正常运行,但在移动和台式机的Safari和Firefox浏览器中均无法运行。

脚本

$('.announation').each(function(i) {
$('.announation').eq(i).on('click touchstart', function(e) {
                $(
                    '.one,.two,.three,.four,.five,.six,.seven,.eight,.nine,.ten,.ele'
                ).eq(i).css({
                    top: 0,
                    left: document.getElementById(e.srcElement.id).offsetLeft - 380
                }).show();
                document.getElementById(e.srcElement.id).innerText = "x";
                $('#' + e.srcElement.id).addClass("active");
            });
});

HTML:

   <div class="annotationsmark">
    <div class="announation" alt="one" id="oneA">+</div>
    <div class="announation" alt="two" id="twoA">+</div>
    </div>

    <div id="messages">
         <div class="one">One</div>
         <div class="two">two</div>
    </div>

我尝试了多种方法:

没用:

$(document.body).on( "click touchstart", ".announation", function() { });

没用:

$('body .announation').eq(i).on('click touchstart', function(e){});

没用:

$('.annotationsmark').on('click', '.announation', function(e) {
var i=$(this).index();
});

问题可能是由于srcElement 。Firefox和Safari可能不支持此功能。 尝试将srcElementtarget e.srcElement.ide.target.id

或者,您可以创建一个变量并使用该变量

var target = event.target || event.srcElement;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM