我試圖獲得選擇框的值,但它始終爲我帶來第一個值。選擇框未正常工作後初始化
在開始時,select是空的。我按下一個顯示模式的按鈕並加載選擇框的信息。我想,問題就來了,因爲我直到按鈕被按下,因爲我與另一個選擇嘗試,效果不錯
我不加載選擇選項是這樣的模式:
<div class="modal fade" id="myModalPremios" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Premios</h4>
</div>
<div id="premios" class="modal-body">
<jsp:include page="../frag/premios-list-frag.jsp"/>
</div>
<div class="modal-footer">
<button class="btn btn-danger" aria-hidden="true" data-dismiss="modal">Ok</button>
</div>
</div>
</div>
</div>
這是形式該模式中:
<form class="form-horizontal" role="form">
<div class="form-group">
<input type="hidden" id="id" name="quiniela.id" value="${quiniela.id }"/>
</div>
<div class="form-group">
<label for="plantillaOwnerQuiniela" class="col-sm-4 control-label">Quiniela</label>
<div class="col-sm-5">
<select class="form-control" name="quiniela.plantillaOwnerQuiniela" id="plantillaOwnerQuiniela" ${read }>
<c:forEach items="${lista2 }" var="pl">
<option value="${pl.id }"
<c:if test="${pl.id == quiniela.plantillaOwnerQuiniela.id}">selected="selected"</c:if>>${pl.nombrePlantillaOwner} - ${pl.precioQuiniela}Bs</option>
</c:forEach>
</select>
</div>
</div>
</form>
這是我的顯示模式:
$("#myModal").modal("show");
我已經讀過,也許該元素不存在於Dom,然後我試着使用這個函數來看看是否發生了什麼,但它不起作用。
$('#plantillaOwnerQuiniela').on('change',function() {
var selectVal = $('#plantillaOwnerQuiniela :selected').val();
alert(selectVal);
});
我使用的引導模式3。我真的無法弄清楚如何來試試你的答案跟我的代碼,我告訴我的模式diferently – xpiero
它不會工作,因爲我正在使用的struts2也..我填充選擇框數據調用一個動作,當我顯示模式 – xpiero