addEventListener()方法有什么问题? [英] what is wrong with addEventListener() method?
本文介绍了addEventListener()方法有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下htmla和javascript代码有什么问题?
I What is wrong with the following htmla and javascript code?
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click me.</p>
<script>
document.getElementById("demo").addEventListener("click", m);
function m() {
var a=document.getElementById("demo").innerHTML;
var b="";
for (i=0; i<a.length; i++)
{
if (a.charCodeAt(i)>65 && a.charCodeAt(i)<=90)
{
b=b+a.charAt(i).toLowerCase();
}
else
b=b+a.charAt(i).toUpperCase();
}
alert(b);
}
}
</script>
</body>
</html>
推荐答案
缺少开头括号:
Opening bracket for else is missing:
else
{
此功能没有问题,但是......什么是你在做?在调用addEventListener
时,对象m
(函数)尚未初始化。移动此电话将其置于m = ...
-SA
Nothing is wrong with this function, but… What are you doing? At the moment of the call toaddEventListener
, the objectm
(function) is not yet initialized. Move this call to put it afterm = …
—SA
我希望将click me转换为小写或大写
i want convert "click me" to lower case or upper case
这篇关于addEventListener()方法有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文