javascript - 单击提交输入时如何防止 Accordion 切换?

标签 javascript jquery html twitter-bootstrap accordion

当我点击一个提交 POST 表单的图标时,我不知道如何防止 accordion 的默认行为。

<tr data-toggle="collapse" data-target="#record_309" class="accordion-toggle even">

                            <td>
                            </td>
                            ...
                            <td class="action">                                      
<div class="col-lg-12">
    <form class="col-lg-3" action="/dashboard/settings/" method="get">
        <input type="hidden" name="product_id" value="309">
        <input style="max-width:15px;" type="image" onclick="preventAccordion(event);" src="/static/icons/alarm-1.png">
    </form>
    <form class="col-lg-3" action="/products/reset/" method="post"><input type="hidden" name="csrfmiddlewaretoken" value="<CSRFTOKEN>">
        <input type="hidden" name="product_id" value="309">
        <input style="max-width:15px;" type="image" src="/static/icons/restart.png">
    </form>    
</div>        
</td>        
</tr>

如您所见,在最后一列的第一种形式中,我试图调用 preventAccordion(e) 函数来防止显示 Accordion 。问题是 preventDefault(event) 阻止了表单提交。

<script>
        window.preventAccordion = function(e) {
            e.preventDefault();
        }
</script>

你知道当用户点击这个图标时如何防止 Accordion 切换吗?

最佳答案

改用e.stopPropagation()

Note that this will not prevent other handlers on the same element from running. http://api.jquery.com/event.stopPropagation

示例:http://jsfiddle.net/1o78c2os/2/

关于javascript - 单击提交输入时如何防止 Accordion 切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42520247/

相关文章:

javascript - jQuery:$.ajax() 重定向到其 URL 表单操作参数,而不是对表单操作执行 AJAX 请求

javascript - 两个下拉列表,第二个下拉列表填充数据库中的值

javascript - 如何访问对象数组中对象的特定属性?

javascript - 检查浏览器对特定 Mime 类型的支持?

javascript - jquery获取上面div中select的值

javascript - 获取 div 元素内高度相等的列表

html - 在页面调整大小时堆叠导航按钮

javascript - 即使数组长度为 1,循环传递三次的简写?

javascript - 带数字的数据属性名称

Javascript/YUI 字符计数器减一