Javascript jquery选择一个按钮
我有一个html页面,其中包含几个引导模式。我想使用jquery关闭它们。但是,我在选择它们时遇到了困难 这是html的一个示例:Javascript jquery选择一个按钮,javascript,jquery,coffeescript,Javascript,Jquery,Coffeescript,我有一个html页面,其中包含几个引导模式。我想使用jquery关闭它们。但是,我在选择它们时遇到了困难 这是html的一个示例: <div class="modal-footer span5"> <input class="btn btn-primary" name="commit" type="submit" value="Save Material"> </div> 或者这个: $(".modal-footer .btn").click.eac
<div class="modal-footer span5">
<input class="btn btn-primary" name="commit" type="submit" value="Save Material">
</div>
或者这个:
$(".modal-footer .btn").click.each ->
alert 'commit'
$(this).modal "hide"
谢谢 这不是javascript代码。试试这个:
$(".modal-footer .btn").click(function(){
alert('commit');
$(this).parent().hide();
});
无论如何,我不明白,如果bootstrap自动关闭模态,为什么要用jquery关闭模态。这不是javascript代码。试试这个:
$(".modal-footer .btn").click(function(){
alert('commit');
$(this).parent().hide();
});
无论如何,我不明白,如果bootstrap自动关闭模态,为什么要用jquery关闭模态。JS引擎不会解释Coffeescript。相反,需要先将该块编译成javascript。或者您可以直接编写javascript 如果.modal footer类来自默认引导模式,这意味着它只是整个模式html块的一部分,那么页脚可能不是附加处理程序以关闭它的最佳位置 开箱即用的bootstrap具有如下默认模式结构:
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria- labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
如果没有,您可以使用.parent调用字符串遍历树,就像前面响应中的示例一样
除非我错过了什么 JS引擎不解释Coffeescript。相反,需要先将该块编译成javascript。或者您可以直接编写javascript 如果.modal footer类来自默认引导模式,这意味着它只是整个模式html块的一部分,那么页脚可能不是附加处理程序以关闭它的最佳位置 开箱即用的bootstrap具有如下默认模式结构:
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria- labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
如果没有,您可以使用.parent调用字符串遍历树,就像前面响应中的示例一样
除非我错过了什么 我在Rails中使用了一个简单的表单,但我还无法让引导程序在提交时关闭模式。所以,我尝试了另一种方式。我在同一个html页面上有多个模式页脚。我不需要包含。每种方式都是这样吗?不,您在选择器中使用了一个类,因此该类的所有元素都将被选择。我在Rails中使用了一个简单的表单,但我无法在提交时让Bootstrap关闭模式。所以,我尝试了另一种方式。我在同一个html页面上有多个模式页脚。我不需要包括。每种方式都有吗?不,您正在选择器中使用一个类,因此将选择该类的所有元素。$'myModal'.modal'hide'-这可能不起作用-我在同一页面上编辑了多个引导模式以更正错误:$.modal footer.btn.clickfunction{alert'commit';$this.parent.parent.modal'hide'};$'myModal'.modal'hide'-这可能不起作用-我在同一页面上编辑了多个引导模式以更正错误:$.modal footer.btn.clickfunction{alert'commit';$This.parent.parent.modal'hide';};