为什么我不能以这种方式使用bootstrap可编辑表?
<table id="addElements" data-height="299">
<thead>
<tr>
<th data-field="id" data-align="right">Item ID</th>
<th data-field="element" data-align="center">Element</th>
<th data-field="weight" data-align="">Težina</th>
<th data-field="default_thickness" data-align="">Debljina</th>
</tr>
</thead>
</table>
//put data in js variable and fill the table
var elementData = [{
"id": "1",
"element": "c",
"weight": "20",
"default_thickness": "6"
}, {
"id": "2",
"element": "k",
"weight": "21",
"default_thickness": "2"
}, {
"id": "3",
"element": "p",
"weight": "18",
"default_thickness": "2"
}];
$(function () {
$('#addElements').bootstrapTable({
data: elementData
});
})
$.fn.editable.defaults.mode = 'inline';
$('td').editable({
url: '/post',
type: 'text',
pk: 1,
name: 'parket',
title: 'Enter username'
});
在这个小提琴中 https://jsfiddle.net/aleksacavic/03agu1ex/1/ 单击时,表格单元格处于编辑模式。但是我网站上的相同代码无效?我错过了什么?正如我所看到的,在我看来,单击时,不允许单元格更改类,只有表格线程突出显示,没有创建其他元素(输入字段)。 感谢
答案 0 :(得分:3)
你错过了就绪函数,因为这个jquery无法绑定数据。
//put data in js variable and fill the table
$(window).bind("load", function() {
var elementData = [{
"id": "1",
"element": "c",
"weight": "20",
"default_thickness": "6"
}, {
"id": "2",
"element": "k",
"weight": "21",
"default_thickness": "2"
}, {
"id": "3",
"element": "p",
"weight": "18",
"default_thickness": "2"
}];
$(function () {
$('#addElements').bootstrapTable({
data: elementData
});
})
$.fn.editable.defaults.mode = 'inline';
$('a').editable({
url: '/post',
type: 'text',
pk: 1,
name: 'parket',
title: 'Enter username'
});
$('td').editable({
url: '/post',
type: 'text',
pk: 1,
name: 'parket',
title: 'Enter username'
});
});
答案 1 :(得分:0)
尝试在加载时添加延迟,应该修复它:
setTimeout(function(){
$.fn.editable.defaults.mode = 'inline';
var a = $('a');
$('a').editable({
type: 'text',
pk: 1,
name: 'parket',
title: 'Enter username'
});
$('td').editable({
type: 'text',
pk: 1,
name: 'parket',
title: 'Enter username'
});
},500);