【问题标题】:X-editable $(...).editable is not a functionX-editable $(...).editable 不是函数
【发布时间】:2017-08-24 11:03:55
【问题描述】:

我有

 <tr>
     <td><i class="fa fa-folder-o" aria-hidden="true"></i>Site</td>
     <td>
         <a href="{{$url}}" id="username" data-type="string" data-pk="1" data-name="username" data-url="post.php" data-toggle="#pencil" data-default="'click'">{{$url}}</a>
         <a href="#" id="pencil" style="float: right"><i class="fa fa-pencil"></i></a>
     </td>
</tr>

<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="/js/bootstrap-editable.js"></script>

<script>

   $(function(){
   $('#pencil').click(function(e){
       e.stopPropagation();
       $('#username').editable('toggle');
       $('#pencil').hide();
    });
    $(document).on('click', '.editable-cancel, .editable-submit', function(){
       $('#pencil').show();
    });
 });
</script>

结果:Uncaught TypeError: $(...).editable is not a function ($('#username').editable('toggle'); - 这里)

但是当我只有$('#username').editable(); 时,一切正常,默认情况下,但是在这个元素上。当我点击按钮 (#pencil) 时需要它工作时。

有人可以帮助我吗?我已经在这方面花费了很多时间。而且我真的看不出有什么问题。

【问题讨论】:

  • 这看起来不可能,你确定正在加载boostrap-editable.js 吗?
  • 是的,正在加载中
  • 我现在尝试将&lt;script src="/js/bootstrap-editable.js"&gt;&lt;/script&gt;更改为&lt;script src="//cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.0/bootstrap3-editable/js/bootstrap-editable.min.js"&gt;&lt;/script&gt;。同样的错误。
  • 可以传入字符串吗?另外,您是在运行本地服务器还是直接访问文件?请确保 javascript 加载为 .editable is not a function 意味着它不太可能。
  • 以牺牲字符串为代价,现在已经不那么重要了(但是默认手动表是真的)。我在本地服务器上启动一切。是的 .editable 被加载为 JS 函数。在此之前她工作的事实。 (正如我之前写的,它可以工作,但是当我开始使用 toggl 构建结构时,它停止了)

标签: javascript jquery html x-editable


【解决方案1】:

对于在 asp.net mvc 部分视图上遇到此错误的人,我通过仅在主视图中添加引用来解决此问题。

我在所有局部视图中添加了 jquery 和 xeditable 引用,它们相互冲突。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-06
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    相关资源
    最近更新 更多