IE 11中的onClick不能与单击一起使用

编程入门 行业动态 更新时间:2024-10-26 23:36:55
本文介绍了IE 11中的onClick不能与单击一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当用户单击视频上的任意位置时,我正在尝试播放/暂停视频.问题在于,它可以在IE 11中双击运行,对于所有其他浏览器,只需单击一次即可完美运行.以下是我的代码.

I am trying to play/pause the video when a user clicks anywhere on the video. The problem is that it is working on the double click in IE 11 and for all the other browsers, it is working perfectly with single left click. Following is my code.

var obj = "<object id=\"video\" onClick=\"clicked('video')\" data=\"data:application/x-silverlight-2,\" type=\"application/x-silverlight-2\" width=\"" + width1 + "%\" height=\"" + height1 + "%\">" + "<param name=\"onLoad\" value=\"pluginLoad\" />" + "<param name=\"source\" value=\"player.xap\"/>" + "<param name=\"initParams\" value=\"sourceurl=" + url + "\" />" + "</object>";

videoClicked方法如下"

videoClicked method is as follows"

function clicked(ID) { $("video").css("cursor", "pointer"); var mediaElementName = "mediaPlayer"; var host = document.getElementById(ID); var s = host.content.findName(mediaElementName).CurrentState; if (s == "Paused") host.content.findName(mediaElementName).Play(); else host.content.findName(mediaElementName).Pause(); }

我希望它可以通过单击鼠标左键来工作.当我使用onmousedown时,它也可以在IE 11上正常运行.谁能告诉我我的代码出了什么问题?

I want it to work with a single left click. When I am using onmousedown, it is working perfectly on IE 11 as well. Can anyone tell me what is wrong with my code?

谢谢.

推荐答案

您不应该附加html中的处理程序,也不要自己附加.您将了解这些跨浏览器问题.

You shouldn't want to attach the handlers in html, or by yourself. You'll get into loads of these cross browser issues.

尝试一下:

$("#video").mouseup(function(e) { if (e.which != 1) return false; // Stops all non-left-clicks alert("clicked"); });

更多推荐

IE 11中的onClick不能与单击一起使用

本文发布于:2023-10-30 18:52:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1543702.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:能与   单击   onClick

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!