Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery.mouseover()不工作(捕捉我)_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript Jquery.mouseover()不工作(捕捉我)

Javascript Jquery.mouseover()不工作(捕捉我),javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在做作业jquery,我试图在mouseover中添加更多内容,但没有效果 $(“按钮”).mouseover(函数(){ $(this.css)({ 左:(Math.random()*300)+“px”, 顶部:(Math.random()*300)+“px”, }, 1); }); 按钮{ 位置:绝对位置; 顶部:400px; 左:500px; } 如果你能抓住我! 这是因为每个元素的默认位置是静态的,它不会对顶部、左侧、右侧或底部样式产生任何影响 默认情况下,HTML元素是静态的

我正在做作业jquery,我试图在mouseover中添加更多内容,但没有效果

$(“按钮”).mouseover(函数(){
$(this.css)({
左:(Math.random()*300)+“px”,
顶部:(Math.random()*300)+“px”,
}, 1);
});
按钮{
位置:绝对位置;
顶部:400px;
左:500px;
}

如果你能抓住我!

这是因为每个元素的默认
位置是
静态的
,它不会对
顶部
左侧
右侧
底部
样式产生任何影响

默认情况下,HTML元素是静态的

静态定位的图元不受顶部、底部、左侧和右侧属性的影响

因此,您只需为如下代码片段中的按钮添加
position:relative
position:absolute

$(“按钮”).mouseover(函数(){
$(this.css)({
左:(Math.random()*300)+“px”,
顶部:(Math.random()*300)+“px”,
}, 1);
});
按钮{
位置:相对位置;
}


向我们展示您失败的努力。您尝试过的代码是什么$(“button”).mouseover(function(){$(this).css({left:(Math.random()*300)+“px”,top:(Math.random()*300)+“px”,},1);})@TtVox请编辑您的问题并在那里添加代码/html。正文{width:500px;height:500px;margin:100px auto;}div.main{background color:#ff6;width:400px;height:400px;margin:0 auto;}按钮{位置:相对;}h1{文本对齐:中心;字体系列:笔刷脚本标准;$($)。鼠标悬停(函数(){$(this.css({left:(Math.random()*300)+“px”,top:(Math.random()*300)+“px”,},1);});如果可以的话,抓住我!@TtVox,它在你这边还不起作用吗?你确定你的页面中包含了
jQuery
吗?这行代码
中。你也可以按
F12
来检查
开发工具
,看看是否有任何错误。是的,我检查过了使用jquery。我在eclipse中运行。我不明白为什么不在我的代码上运行。@TtVox在
开发工具
中是否有任何
错误
?如果您使用的是Chrome,请按
F12
,然后转到
控制台
选项卡。如果有任何错误,请将错误复制到此处,谢谢@Kyojimaru。此错误:Uncaught ReferenceError:$:$不是定义