【问题标题】:Object [object Object] has no method 'datepicker'对象 [对象对象] 没有方法 'datepicker'
【发布时间】:2014-02-07 10:34:04
【问题描述】:

我的问题是当我自己运行 datepicker.php 时它工作正常 但是当我试图从另一个(测试按钮)打开页面时,我得到了这个错误

Object [object Object] 没有方法'datepicker'

我认为这是 jquery ui 到 jquery mobile 之间的冲突,即使我没有在 datepicker 页面中加载它。

使用 jquery mobile 的第一页有几个按钮和一些 php 多了一个测试按钮:

<a href="datepicker.php" type=button data-theme="b" data-role="button">test</a>

datepicker.php:

    <html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Datepicker - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">

  <script src="//code.jquery.com/jquery-1.9.1.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

</head>
<body>

<p>Date: <input type="text" id="datepicker"></p>

 <script type="text/javascript">
$( "#datepicker" ).datepicker();

</script>

</body>
</html>

我已经尝试过几种非冲突方式,但没有帮助:(

  $(function () {
var jq = $.noConflict();
    $( "#datepicker" ).datepicker({});
  }); 

【问题讨论】:

    标签: jquery jquery-ui jquery-mobile


    【解决方案1】:

    这是因为noConflict()调用,一旦调用$就不再指代jQuery了。

    另外,也不需要在 dom 就绪时调用它,所以试试

    //call noConflict()
    var jq = $.noConflict();
    //$ no longer refers to jQuery, so use the variable jQuery/jq to refer to jQuery
    jQuery(function ($) {
        //the dom ready handler receices the jQuery instance as the parameter, so name it as $ so that we can use $ inside the handler to refer to jQuery
        $("#datepicker").datepicker({});
    });
    

    演示:Fiddle

    【讨论】:

    • 我试过了,但仍然出现同样的错误;/
    【解决方案2】:

    在任何页面上加载 js 是个问题
    只需要添加到索引头

    <script src=..js
    

    ....

    ;/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多