[英]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.