简体   繁体   English

onclick 功能在 IE 中不起作用,但在其他浏览器上工作正常

[英]The onclick function is not working in IE but works fine on other browsers

I need to open a div on click of an image, so for this I simply created an onclick event for a function within image tag.我需要在单击图像时打开一个 div,因此为此我简单地为图像标记中的函数创建了一个onclick事件。 When I click on the image it shows that 'the function is undefined' .当我单击图像时,它显示'the function is undefined' The same code works fine on other browsers but not on IE.相同的代码在其他浏览器上工作正常,但在 IE 上不工作。 I really need help on this.我真的需要这方面的帮助。 Tried multiple things with reference to the similar questions asked here but nothing seems working.参考此处提出的类似问题尝试了多种方法,但似乎没有任何效果。 Any help would be appreciated.任何帮助,将不胜感激。

Below is the code I tried下面是我试过的代码

HTML HTML

<div class="chat-bubble" id="chat-bubble">
   <div id="chat-header">
      <img src="images/Chatbot-icon.png" id="chat-icon" /><span> YODA </span
      ><img
         src="images/close.png"
         id="close-icon"
         onclick="closeFunction()"
      />
   </div>
   <div id="webchat" role="main" class="webchat"></div>
   <div id="botchat" role="main" class="webchat"></div>
   <img
      src="images/Chatbot-icon.png"
      id="chatBubble"
      onClick="javascript: myFunction();"
   /><img
      src="images/Chatbot-icon.png"
      id="Bubble"
      onmousedown="myChat();"
   />
</div>


Javascript Javascript

function myChat() {
   var a = document.getElementById("botchat");

   var b = document.getElementById("chat-header");

   var c = document.getElementById("body");
   document.getElementById("Bubble").style.display = "none";
   if (a.style.display == "block") {
      a.style.display = "none";
   } else {
      a.style.display = "block";
   }
   if (b.style.display == "block") {
      b.style.display = "none";
   } else {
      b.style.display = "block";
   }
   c.style.height = "100vh";
   c.style.overflowY = "hidden";
}

After formatting your code I have found that you have missed myFunction() and closeFunction() in your code.格式化代码后,我发现您在代码中遗漏了 myFunction() 和 closeFunction()。

Paste your code for those functions.粘贴这些函数的代码。

 function myChat() { var a = document.getElementById("botchat"); var b = document.getElementById("chat-header"); var c = document.getElementById("body"); document.getElementById("Bubble").style.display = "none"; if (a.style.display == "block") { a.style.display = "none"; } else { a.style.display = "block"; } if (b.style.display == "block") { b.style.display = "none"; } else { b.style.display = "block"; } c.style.height = "100vh"; c.style.overflowY = "hidden"; }
 <div class="chat-bubble" id="chat-bubble"> <div id="chat-header"> <img src="images/Chatbot-icon.png" id="chat-icon"> <span> YODA </ span> <img src="images/close.png" id="close-icon" onClick="closeFunction();"> </div> <div id="webchat" role="main" class="webchat"></div> <div id="botchat" role="main" class="webchat"></div> <img src="images/Chatbot-icon.png" id="chatBubble" onClick="myFunction();"> <img src="images/Chatbot-icon.png" id="Bubble" onmousedown="myChat();"> </div>

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

相关问题 单击事件在 IE 中不起作用,但在其他浏览器中工作正常 - Click event is not working in IE but works fine in other browsers 滑动在IE中不起作用。 但它在所有其他浏览器中都可以正常工作 - Sliding is not working in IE . But it works fine in all other browsers jQuery .load在IE上不起作用(在所有其他浏览器上正常工作) - jQuery .load not working on IE (Works fine on all other browsers) onclick事件在firefox中不起作用,但在IE中可以正常工作 - onclick event not working in firefox but works fine in IE jQuery在IE中不起作用,可在其他浏览器中使用 - jQuery not working in IE, works in other browsers 正则表达式不适用于IE,但适用于其他浏览器 - Regex not working for IE but works for other browsers 我的Javascript代码在IE中不起作用,但在其他浏览器中也可以正常工作 - My Javascript code does not work in IE but works fine in other browsers Ajax在下拉列表中无法在IE8中工作,但在其他浏览器中工作正常 - Ajax not working in IE8 on dropdown but it's working fine in other browsers Javascript无法在IE中运行,但所有其他浏览器都可以正常运行 - Javascript not working in IE, but all other browsers are working fine 简单的javascript褪色效果在IE7 / 8中不起作用,在其他浏览器中效果很好 - Simple javascript fading effect not working in IE7/8, fine in other browsers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM