简体   繁体   English

Javascript 函数适用于 JSFiddle 但不适用于我的 HTML 文档?

[英]Javascript function works on JSFiddle but not in my HTML document?

So, I found a code/function I wanted to use on this site here: stackoverflow所以,我在这里找到了一个我想在这个网站上使用的代码/函数: stackoverflow

I then copied the code from the second answer, did some small changes and tested if it actually worked, and I found out it did not.然后我从第二个答案中复制了代码,做了一些小改动并测试了它是否真的有效,我发现它没有。 All of the functions from the link work on JSFiddle tho, but none of them work for me in my html document.链接中的所有功能都适用于 JSFiddle tho,但在我的 html 文档中没有一个对我有用。

I did < script>, didn't work.我做了<脚本>,没用。 I tried to make a separate .js document, but the code was still not working.我试图制作一个单独的 .js 文档,但代码仍然无法正常工作。

<body>

<div id="bokse2"></div>
<div id="boksi"></div>

<script src="test.js" type="text/javascript"></script>
<script>

$(function() {
$('#bokse2').click(function() {
    $('#boksi').css('margin-left', '-=10px');
});
});

</script>
</body>

The big box (boksi) should move 10 pixels to the left by clicking on the smaller box (bokse2).单击较小的框 (bokse2),大框 (boksi) 应向左移动 10 个像素。 Just like it does here: JSFiddle就像这里一样: JSFiddle

您缺少 jQuery 的包含

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM