我有一个表单,可以手动给出值,也可以从下拉列表中的预定义集合中给出值。 使用下拉列表时。这些值用$ .val()填充。提交from时,帖子没有参数 我的HTML格式:
<form class="form-horizontal" role="form" action="/android/test/connection/form/" method="post">
<div class="control-group has-feedback">
<label for="name" class="control-label">Servernaam</label>
<div class="controls">
<input type="text" disabled="disabled" id="name" name="name" value="" />
</div>
</div>
<div id="ipAddress-row" class="control-group error">
<label for="ipAddress" class="control-label">IP adres</label>
<div class="controls">
<input type="text" id="ipAddress" name="ipAddress" value="" />
</div>
</div>
<div id="tcpPort-row" class="control-group error">
<label for="tcpPort" class="control-label">Poort</label>
<div class="controls">
<input type="text" id="tcpPort" name="tcpPort" value="" />
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn">Reset</button>
</div>
</div>
</form>
和下拉列表
<div id="serverDropdown" class="offset1 btn-group">
<button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<span>Known Servers</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li role="presentation">
<a role="menuitem" href="#" tabindex="-1">Server 1</a>
<input type="hidden" name="ipAddress" value="127.0.0.1" />
<input type="hidden" name="tcpPort" value="8600" />
<input type="hidden" name="protocol" value="2" />
</li>
</ul>
</div>
用于填写输入的javascript:
$('#serverDropdown ul li a').click(function() {
var item, inputs;
removeErrors();
item = $(this).parent();
$('#name').val($(this).text());
$('#ipAddress').val($(item).find('input[name=ipAddress]').val());
$('#tcpPort').val($(item).find('input[name=tcpPort]').val());
$('#protocol').val($(item).find('input[name=protocol]').val());
});