html select标签获取value和name属性
form关键代码
<form id="form" action="#" method="get" class="form-horizontal"/>
<input type="hidden" id="productId" name="productId" value="${ obj.productId}"/>
<input type="hidden" id="productName" name="productName"/>
<div class="control-group">
<label class="control-label">景区名称</label>
<div class="controls">
<select id="productSelect">
<option value="">请选择景区...</option>
<c:forEach items="${scenicList}" var="o" varStatus="s">
<option data-name="${o.name }" value="${o.id }">(${s.index+1}) ${o.name }</option>
</c:forEach>
</select>
</div>
</div>
js代码
$(document).ready(function () {
$('#productSelect').change(function(data){
var value = data.currentTarget.selectedOptions[0].value;
var text = data.currentTarget.selectedOptions[0].dataset['name'];
$('#productId').val(value);
$('#productName').val(text);
});
});