[英]How do I make a JQuery close a button?
您好,我正在尝试制作一个JQuery代码以关闭我的错误按钮,但是如果您能帮助您,我这样做会遇到问题。 请放轻松,因为我只是在学习JQuery的知识。
这是我的php / html代码
<?php if(isset($template->form->error)) { ?>
<div class="flash" style="margin-top: 20px;"></div>
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<h4>Warning!</h4>
<?php echo $template->form->error; ?>
</div>
<?php } ?>
我试图做到这一点,所以当您单击(x)×
错误弹出窗口消失了,我尝试了这个JQuery代码
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$(".close").remove(); // The close is the class and not the id (Thank you jsexpert and Darren)
});
});
</script>
可能是因为我的登录名提交了吗? 这是我的登录按钮/登录提交
<div><input class="btn btn-primary" name="login" type="submit" value="Login"></div>
对不起,我没说清楚。 http://prntscr.com/433iza警告! 我想要通过单击右侧的x按钮来摆脱的东西。 全部$(“。close”)。remove(); 确实是这个http://prntscr.com/433lfh
我认为这是您的问题:
$("#close").remove();
应该:
$(".close").remove(); // The close is the class and not the id
看起来您正在使用引导程序? ( 如果我错了,请纠正我 )?
在这种情况下,您希望您的绑定使用trigger()
$(".close").trigger("click");
另外另一个问题是按钮是一个class (.)
而不是 id (#)
。
如果不是这种情况,最好将其绑定到特定的按钮:ie-
$("button.close").click(function(){
$('#close').remove();
});
另外,我在任何地方都看不到带有#close
的元素?
正如其他人指出的那样,您的选择器是错误的。 但这是另一种方法。
$(function(){
$( ".close" ).click(function( event ) {
event.preventDefault();
$( this ).hide();
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.