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