好的,所以当我尝试使用hide()和类似的东西时,jquery工作正常但是当我尝试使用submit()时没有任何反应!
如果有人帮助我,我会非常感激。
这是我的表格:
<form class = "form-horizontal" action = "demo.php" method="post" id = "contactform" >
<div class = "modal-header">
<h4> Sign up for newsletter!</h4>
</div>
<div class = "modal-body">
<div class = "form-group">
<label for = "contact-name" class = "col-lg-2" control-label>Name:</label>
<div class = "col-lg-10">
<input type = "text" class = "form-control" id = "contact-name" name="contact-name" placeholder = "Full name" value = "">
</div>
</div>
<div class = "form-group">
<label for = "contact-email" class = "col-lg-2" control-label>Email:</label>
<div class = "col-lg-10">
<input type = "email" class = "form-control" id = "contact-email" name = "contact-email" placeholder = "u@example.com">
</div>
</div>
<div class = "form-group">
<label for = "contact-name" class = "col-lg-2" control-label>Name:</label>
<div class = "col-lg-10">
<textarea class = "form-control" rows = "8"> </textarea>
</div>
</div>
</div>
<div class = "modal-footer">
<a class = "btn btn-default" data-dismiss = "modal">Close</a>
<button class = "btn btn-primary" type = "button" name = "submit" id = "submit" >Submit thiscarp</button>
</div>
</form>
这是我的Jquery代码
<script type = "text/javascript">
$(document).ready(
function(){
$("button#submit").click(function()
{
$("form#contactform").submit();
});
});
</script>
我也有这个想法
<head>
<title> Bootstrap 3 </title>
<meta name = "viewport" content = "width=device-width, initial-scale=1.0">
<link href = "css/bootstrap.min.css" rel = "stylesheet">
<link href = "css/styles.css" rel = "stylesheet">
<script src="js/jquery-1.11.1.js"></script>
<script src="js/bootstrap.js"></script>
</head>
答案 0 :(得分:0)
<script type = "text/javascript">
$(document).ready(function(){
$("#submit").click(function(){
$("#contactform").submit();
});
});
</script>
更改为$("#contactform").submit();
,因为您使用了错误的选择器以及按钮选择器
答案 1 :(得分:0)
解决了!
按钮ID无法提交。
我改变了
<button class = "btn btn-primary" type = "button" name = "submit" id = "submit" >Submit thiscarp</button>
到
<button class = "btn btn-primary" type = "button" name = "connect" id = "connect" >Submit thiscarp</button>