Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何从外部JS文件中检测样式元素onclick?_Jquery - Fatal编程技术网

Jquery 如何从外部JS文件中检测样式元素onclick?

Jquery 如何从外部JS文件中检测样式元素onclick?,jquery,Jquery,我对JS的了解相当有限,但我们在页面上有一个操作,它会导致外部JS文件中出现if语句。我正在使用(event.toElement),它可以在chrome中工作,但不能在ie、ff或opera中工作 内联js $("div#jquery-live-search .dialog-iframe-card").dialog2IFrame( { height:900, closeOnOverlayClick: true,

我对JS的了解相当有限,但我们在页面上有一个操作,它会导致外部JS文件中出现if语句。我正在使用(event.toElement),它可以在chrome中工作,但不能在ie、ff或opera中工作

内联js

    $("div#jquery-live-search .dialog-iframe-card").dialog2IFrame(  { 
            height:900,
              closeOnOverlayClick: true, 
              closeOnEscape: true, 
              removeOnClose: true, 
              showCloseHandle: true,
}); 

    $("div#jquery-live-search .dialog-iframe-report").dialog2IFrame(    { 
                height:900,
                  closeOnOverlayClick: true, 
                  closeOnEscape: true, 
                  removeOnClose: true, 
                  showCloseHandle: true,
    }); 
    }); 
外部js

var parentHtml = "";
            if ($(event.toElement).hasClass("dialog-iframe-card")) {
            parentHtml = $(__DIALOG_HTML_CARD);
            } else if ($(event.toElement).hasClass("dialog-iframe-report")) {
            parentHtml = $(__DIALOG_HTML_REPORT);
            }
parentHTML在js文件的开头有一个变量,在if语句进行切换时加载该变量。在chrome以外的浏览器中工作时,我似乎不知道如何将正确的操作传递到外部文件

我还尝试了以下只对chrome有效的方法

var $target = $(event.target);
                if ($target.hasClass("dialog-iframe-card")) {
                parentHtml = $(__DIALOG_HTML_CARD);
                } else if ($target.hasClass("dialog-iframe-report")) {
                parentHtml = $(__DIALOG_HTML_REPORT);
                }
这个问题不是重复的,因为建议的答案不是 解决问题。没有解决问题,谢谢


外部js是如何调用的?你是说路径是什么?我们只需包含该文件,当单击与类dialog iframe report或dialog iframe card的链接时,通过$(“div#jquery live search.dialog iframe report”).dialog2IFrame({@ArunPJohny
var$target=$(event.target)调用事件
应该适用于所有浏览器。需要注意的是,Chrome会在回调函数的parameter@UmairP感谢您的反馈,正如您所看到的,我已经尝试了var$target=$(event.target);在外部js文件中。它可以在chrome中使用,但不能在其他浏览器中使用。请发布包含
var$target=$(event.target);