x-editable 在 django 中无法与 bootstrap 3 一起使用
x-editable not working with bootstrap 3 in django
我正在尝试将 x-editable
库集成到我的 Web 应用程序中,以便我可以在我的页面上创建可编辑的元素
我已按照 X-editable
的 official link 中的步骤操作
(只是 frontEnd
部分)
这是我模板中的代码:
{% block extra_stylesheets %}
<link href="{% static "data_management/plugins/bootstrap/css/bootstrap.min.css" %}" rel="stylesheet" />
<link href="{% static 'data_management/plugins/DataTables/media/css/dataTables.bootstrap.min.css' %}"
rel="stylesheet"/>
<link href="{% static 'data_management/plugins/DataTables/extensions/Responsive/css/responsive.bootstrap.min.css' %}"
rel="stylesheet"/>
<link href="{% static 'data_management/plugins/bootstrap-editable/css/bootstrap-editable.css' %}" rel="stylesheet">
{% endblock %}
{% block extra_head_javascript %}
<script src="{% static "data_management/plugins/jquery/jquery-1.9.1.min.js" %}"></script>
<script src="{% static 'data_management/plugins/bootstrap/js/bootstrap.min.js' %}"></script>
<script src="{% static 'data_management/plugins/bootstrap-editable/js/bootstrap-editable.min.js' %}"></script>
{% endblock%}
{% block content %}
<table class="table table-stripped">
<tr>
<th class="text-center">Visit Identifier</th>
<th class="text-center">Visit Date<br/>
<small style="font-weight: normal;">(Click to change the date)
</small>
</th>
</tr>
{% for course in course.books_set.all %}
<tr>
<td class="text-center">{{ course.name }}</td>
<td class="text-center"><a href="#" id="pub_date" data-type="combodate"
data-value="1984-05-15" data-format="YYYY-MM-DD"
data-viewformat="DD/MM/YYYY"
data-template="D / MMM / YYYY" data-pk="1"
data-title="Select published Date "
class="editable editable-click editable-open"
data-original-title="" title=""
style="background-color: rgba(0, 0, 0, 0);">12/12/2012</a>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}
并且我已将此脚本集成到模板的页脚中:
<script>
$(document).ready(function() {
$('#pub_date').editable();
});
</script>
但我不知道为什么这不起作用?
非常感谢任何帮助
编辑
我注意到问题可能是因为 id 重复了,因为我有一个 for loop
并且 id 必须是唯一的!
我怎样才能避免这种情况?
有没有办法创建一个 class 并通过 class 调用所有元素?我不太擅长 css
和 html
.
提前致谢
我已经解决了这个问题:
将x-editable
的版本改为1.5适配bootstrap 3
删除id="pub_date"
并按data-name="pub_date"
切换
并放置此脚本:
<script>
$.fn.editable.defaults.mode = 'popup';
$(document).ready(function() {
$('[data-name=pub_date]').editable();
});
</script>
希望对其他人有所帮助。
我正在尝试将 x-editable
库集成到我的 Web 应用程序中,以便我可以在我的页面上创建可编辑的元素
我已按照 X-editable
(只是 frontEnd
部分)
这是我模板中的代码:
{% block extra_stylesheets %}
<link href="{% static "data_management/plugins/bootstrap/css/bootstrap.min.css" %}" rel="stylesheet" />
<link href="{% static 'data_management/plugins/DataTables/media/css/dataTables.bootstrap.min.css' %}"
rel="stylesheet"/>
<link href="{% static 'data_management/plugins/DataTables/extensions/Responsive/css/responsive.bootstrap.min.css' %}"
rel="stylesheet"/>
<link href="{% static 'data_management/plugins/bootstrap-editable/css/bootstrap-editable.css' %}" rel="stylesheet">
{% endblock %}
{% block extra_head_javascript %}
<script src="{% static "data_management/plugins/jquery/jquery-1.9.1.min.js" %}"></script>
<script src="{% static 'data_management/plugins/bootstrap/js/bootstrap.min.js' %}"></script>
<script src="{% static 'data_management/plugins/bootstrap-editable/js/bootstrap-editable.min.js' %}"></script>
{% endblock%}
{% block content %}
<table class="table table-stripped">
<tr>
<th class="text-center">Visit Identifier</th>
<th class="text-center">Visit Date<br/>
<small style="font-weight: normal;">(Click to change the date)
</small>
</th>
</tr>
{% for course in course.books_set.all %}
<tr>
<td class="text-center">{{ course.name }}</td>
<td class="text-center"><a href="#" id="pub_date" data-type="combodate"
data-value="1984-05-15" data-format="YYYY-MM-DD"
data-viewformat="DD/MM/YYYY"
data-template="D / MMM / YYYY" data-pk="1"
data-title="Select published Date "
class="editable editable-click editable-open"
data-original-title="" title=""
style="background-color: rgba(0, 0, 0, 0);">12/12/2012</a>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}
并且我已将此脚本集成到模板的页脚中:
<script>
$(document).ready(function() {
$('#pub_date').editable();
});
</script>
但我不知道为什么这不起作用? 非常感谢任何帮助
编辑
我注意到问题可能是因为 id 重复了,因为我有一个 for loop
并且 id 必须是唯一的!
我怎样才能避免这种情况?
有没有办法创建一个 class 并通过 class 调用所有元素?我不太擅长 css
和 html
.
提前致谢
我已经解决了这个问题:
将
x-editable
的版本改为1.5适配bootstrap 3
删除
id="pub_date"
并按data-name="pub_date"
切换
并放置此脚本:
<script> $.fn.editable.defaults.mode = 'popup'; $(document).ready(function() { $('[data-name=pub_date]').editable(); }); </script>
希望对其他人有所帮助。