【发布时间】:2013-06-18 10:20:50
【问题描述】:
我在一个页面上提交了两个表单,它们都在做同样的事情。
一个在工具栏/导航栏上,另一个在主页上。
我遇到的问题是,一旦我在工具栏上添加了表单,主页上的表单在触发时就永远没有搜索值,如果我注释掉工具栏中的表单,那么主页就有了值。
//Toolbar submit
<form>
<div class="input-append">
<input type="text" class="span3" placeholder="Enter name" />
<button type="submit" class="btn-u">Go</button>
</div>
</form>
// Main page submit
<form class="form-inline margin-bottom-5">
<div class="input-append">
<input type="text" class="input-xxlarge" placeholder="Enter class name">
<button type="submit" class="btn-u">Go</button>
</div>
</form>
//JavaScript/JQuery
$("form").submit(function (e) {
var searchTerm = $("input:first").val();
if (searchTerm === '') {
// This part of the code is reached for the second submit,
// I have tried using id on the submit but have the same result
}
【问题讨论】:
标签: javascript jquery