我有自己的婚姻状况。它是一个spring表单select(下拉列表),这些选项是根据前面页面中的选择动态生成的。
我被困在一个特殊的场景中,表单选择在下拉列表中只有一个选项(比如配偶)。如果用户选择了唯一可用的下拉选项(意图更改),我需要显示一条消息,即它不能在这里更改,并且应该在前面的页面中进行更改。
我搜索了很多,但是在jquery?,Jquery .on(‘change’.)中找不到表单、选择、选择或单击事件。)因为下拉列表中只有一个值,并且更改事件不会被触发,这将不符合我的目的。
下面是显示下拉选项和选项的代码:
<!-- Marital Status -->
<html:condition name="marital_status" screen="drivers" model="${SESSION_INFO}">
<div class="formrow">
<div class="formlables padding-top-2">
<label><spring:message code="msg.drivers.marital_status" text="Marital Status" /></label>
</div>
<div class="formhelp padding-top-2">
<html:help enabled="true" model="${SESSION_INFO}" helpMsgKey="msgKeyMaritalStatus" />
</div>
<div id="box-marital_status" class="forminput">
<shtml:select id="maritalStatus" items="${ITEMS_MARITAL_STATUS}" path="driverInfo.maritalStatus"
cssclass="select fixed_width"
style="margin-bottom: 20px; width: 300px;"
tabindex="7"
/>
发布于 2014-08-12 14:53:03
我通过将表单select包装在div中并将其绑定到单击事件来解决这个问题。
$('#box-marital_status').click(function() {
// do something
});
<div id="box-marital_status" class="forminput">
<shtml:select id="maritalStatus" items="${MARITAL_STATUS}" path="driverInfo.maritalStatus"
cssclass="select fixed_width"
style="margin-bottom: 20px; width: 300px;"
tabindex="7"
/>
发布于 2014-08-21 03:24:16
肯定是一个更好的解决方案,而且效果很好。
$('#box-marital_status').mousedown(function() {
if ('2' === $('#driverNum').val()) {
var msPrincipal = '${MA_PRINCIPAL_MARITAL_STATUS}';
var msCurrent = $('#maritalStatus').data('prev');
if (_.contains([ 'M', 'Q' ], msPrincipal) && _.contains([ 'M', 'Q' ], msCurrent)) {
$('#dialog_mstatus_change').dialog('open');
}
}
});
$('#box-marital_status').keydown(function(event) {
if ('40' == event.keyCode && '2' === $('#driverNum').val()) {
var msPrincipal = '${MA_PRINCIPAL_MARITAL_STATUS}';
var msCurrent = $('#maritalStatus').data('prev');
if (_.contains([ 'M', 'Q' ], msPrincipal) && _.contains([ 'M', 'Q' ], msCurrent)) {
$('#dialog_mstatus_change').dialog('open');
}
}
});
https://stackoverflow.com/questions/25255028
复制相似问题