我刚刚开始学习j查询并希望在代码笔中测试它,但我无法得到我想要的结果。 https://codepen.io/Sunny143/pen/MrJqrM
以下是我的HTML代码
<head><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1 /jquery.min.js"></script></head>
<body>
<h1>Hello World!</h1>
</body>
以下是我的j查询代码
$(document).ready(function(){
$("h1").mouseOver(function(){
alert("mouseover the heading");
});
});
请帮我这个,非常感谢你。
编辑:我更改了上面给出的代码笔链接中的代码,因为我的问题已经澄清,所以请不要参考该链接
答案 0 :(得分:1)
如果您看到控制台,代码中会出现语法错误。使用mouseover
代替mouseOver
。
所以只需从以下代码中替换您的代码:
$(document).ready(function(){
$("h1").mouseOver(function(){
alert("mouseover the heading");
});
});
为:
$(document).ready(function(){
$("h1").mouseover(function(){
alert("mouseover the heading");
});
});
答案 1 :(得分:0)
必须将mouseOver
更改为mouseover
,但jQuery在Codepen中运行正常,如此处https://codepen.io/anon/pen/NXdLVJ
$(document).ready(function(){
$("h1").mouseover(function(){
alert("mouseover the heading");
});
});
此外,您可以使用笔的设置并添加外部资源,而不是在<head>
中加载库。
答案 2 :(得分:0)
你不能使用骆驼案。
试
.mouseover()
或尝试
$(document).ready(function(){
$("button").on('mouseover',function(){
$("h1").toggle(1000);
});
});