当前位置 : 主页 > 网页制作 > JQuery >

jquery – jsfiddle上的代码相同但不会在我的服务器上运行?

来源:互联网 收集:自由互联 发布时间:2021-06-15
参见英文答案 How do I put codes from jsfiddle.net into my website?1个 我很困惑.我只是试图测试一个jquery(simpleselect)并让它在jquery上运行正常,但是当我将它上传到我的服务器时…完全不起作用!我
参见英文答案 > How do I put codes from jsfiddle.net into my website?                                    1个
我很困惑.我只是试图测试一个jquery(simpleselect)并让它在jquery上运行正常,但是当我将它上传到我的服务器时…完全不起作用!我发誓它的代码相同,但也许新鲜的眼睛可以帮助.我在这里错过了什么?

这是我上传的代码:

<html>
  <head>
    <link rel="stylesheet" type="text/css" href="https://smartieparts.com/bootstrap/includes/templates/bootstrap/css/stylesheet_jquery.simpleselect.min.css" />
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript" src="https://smartieparts.com/bootstrap/includes/templates/bootstrap/jscript/jscript_jquery.simpleselect.min.js"></script>
    <script type="text/javascript">
      $("#currency-select").simpleselect({
        fadingDuration: 500,
        containerMargin: 100,
        displayContainerInside: "document"
      });
    </script>
  </head>
  <body id="indexHomeBody">
    <select name="currency" id="currency-select">
      <option value="USD">USD</option>
      <option value="EUR">EUR</option>
      <option value="GBP">GBP</option>
      <option value="CAD">CAD</option>
      <option value="AUD">AUD</option>
      <option value="CHF">CHF</option>
      <option value="CZK">CZK</option>
      <option value="DKK">DKK</option>
      <option value="HKD">HKD</option>
      <option value="JPY">JPY</option>
      <option value="NZD">NZD</option>
      <option value="NOK">NOK</option>
      <option value="PLN">PLN</option>
      <option value="SGD" selected="selected">SGD</option>
      <option value="SEK">SEK</option>
      <option value="ILS">ILS</option>
      <option value="MXN">MXN</option>
      <option value="TWD">TWD</option>
      <option value="PHP">PHP</option>
      <option value="THB">THB</option>
    </select>
  </body>
</html>

这是JSfiddle

请注意,JSfiddle具有我从上面的代码中完全复制/粘贴的外部css和js资源.

在JSfiddle页面上,下拉列表已格式化并具有淡入淡出效果.在我的服务器上,它有点格式化,没有淡入淡出.

我已将文件上传到我的服务器,以便您查看. Link

Ref

A page can’t be manipulated safely until the document is “ready.” jQuery detects this state of readiness for you. Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute. Code included inside $( window ).load(function() { ... }) will run once the entire page (images or iframes), not just the DOM, is ready.

在document-ready处理程序中包装您的代码.

Specify a function to execute when the DOM is fully loaded.

<script>
$(function() {
    // Handler for .ready() called. 
    $("#currency-select").simpleselect({
        fadingDuration: 500,
        containerMargin: 100,
        displayContainerInside: "document"
    });
});
</script>
网友评论