因此,我正在使用 Django 创建我的博客,并且正在开发通知系统。我希望当用户单击下拉标记所有通知时看到它的工作并且一切正常但是当我添加 Ajax 时下拉停止工作但 Ajax 工作正常我尝试更改 HTML 中的脚本位置但没有。
使用
- 在本地 Bootstrap 3.3.7
- jquery
Ajax :
<script>
$(document).ready(function() {
$("#n_d").click(function(event){
$.ajax({
type:"POST",
url:"{% url 'seen' %}",
success: function(){
document.getElementById("mcount").innerHTML = 0
}
});
return false;
});
});
</script>
下拉菜单(在导航栏内)
{% if user.is_authenticated %}
<li class="dropdown">
{% notifications request as notifications %}
<a href="#" class="dropdown-toggle" id="n_d" onclick="return x=1" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><i aria-hidden="true" class="fa fa-inbox "> <span class="label label-info" id="mcount">{% noticount request %}</span></i></a>
<ul class="dropdown-menu">
{% load blog_tags %}
{% for notification in notifications %}
<li>
<div class="col-md-3 col-sm-3 col-xs-3"><div class="notify-img"><img src="https://www.awn.com/sites/default/files/styles/userthumbnail_tiny/public/avatar92.jpg?itok=i7013HnC" alt=""></div></div>
<div class="col-md-9 col-sm-9 col-xs-9 pd-l0"><a href="{% url 'detail' notification.post_pk %}">{{ notification.FromUser }} {{ notification.content }}</a></div>
</li>
{% endfor %}
</ul>
</li>
{% endif %}
the weird tags are Django stuff.
最佳答案
看来你的代码有错误!我可以理解你复制粘贴了一些东西,因为它不是很一致。
您有这个 onclick="return x=1"data-toggle="dropdown"
并且您正在监听上面 jQuery 脚本中的另一个 onClick
事件。
有了这个,您将覆盖初始对象 onclick
,并且可能与触发菜单打开的 toggle="dropdown"
发生冲突。
你应该在那里尝试不同的实现。
尝试通过删除 data-toogle="dropdown"
并添加 $($(this).data("target")).modal("show"); 来破解它
而不是 return false
在您的 ajax 代码中。
关于javascript - bootstrap 下拉菜单不适用于 ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46836251/