我目前有一个jquery inplace,根据所选值隐藏某些字段。我需要这个函数来加载,所以如果该值来自db,那么它也应该执行相同的隐藏字段而不再选择它的任务。因此,正如您在jsp代码中看到的那样,我检查了在db中找到的值并为其分配了字段。但是,当页面加载时,即使选中了单选按钮,我仍然必须取消选中并再次检查以使该功能正常工作。请帮忙
if (selected === 'MAI') {
_cache.addresseeFields.removeClass('hide');
} else if (selected === 'ADD') {
_cache.mailerFields.removeClass('hide');
}
};
JSP页面
<c:when test="${DATA_WAREHOUSE != null && DATA_WAREHOUSE == 'DB'
&& DATA_WAREHOUSE_RESPONSE != null && DATA_WAREHOUSE_RESPONSE == 'DB_0' && claim.clOriginatorInd == 'ADD'}">
<input name="mailerAddressee" value="ADD" type="hidden"/>
<label for="rMailer" class="radio-wrap">
<input type="radio" name="maileraddressee" value="MAI" id="rMailer">
I was the mailer
</label>
<label for="rAddressee" class="radio-wrap">
<input type="radio" name="maileraddressee" value="ADD" id="rAddressee" checked>
I was the addressee
</label>
</c:when>
参考的完整JS文件:
define(['jquery', 'fileupload'], function($, fileupload) {
/**
* @name ClaimsMailingInfo
* @returns {function} init
* @namespace
*/
var ClaimsMailingInfo = (function ClaimsMailingInfo() {
var _cache = {
'rMailerAddressee' : null,
'addressKnown' : null,
'mailerFields' : null,
'addresseeFields' : null
},
/**
* @name _init
* initialize the section
*/
_init = function _init() {
// console.log('init mailing info');
_setupCache();
_addEvents();
},
/**
* @name _addEvents
* add event handlers
*/
_addEvents = function _addEvents() {
_cache.rMailerAddressee.change(function() {
var selected = $(this).val();
_updateAddressView(selected);
});
},
_setupCache = function _setupCache() {
_cache.rMailerAddressee = $('input[name=maileraddressee]');
_cache.addressKnown = $('.address-known');
_cache.mailerFields = $('#mailer-wrap');
_cache.addresseeFields = $('#addressee-wrap');
},
/**
* @name _updateAddressView
* @params {boolean} selected
* update the address view based on radio button
*/
_updateAddressView = function _updateAddressView(selected) {
var regAddress = $('#'+ selected + '-address-known'),
addressWrap = $('.address-wrapper'),
infoText = $('.info-text'),
checked = _cache.rMailerAddressee.is(':checked'),
errorWrap = $('.address-sections .error-wrap');
//if a radio button is selected, hide the info text
if (checked) { infoText.addClass('hide'); }
//remove any errors
errorWrap.empty();
//hide all addresses / fields, then show the one we want
_cache.addressKnown.addClass('hide');
addressWrap.addClass('hide');
//reg address
regAddress.removeClass('hide');
//fields
if (selected === 'MAI') {
_cache.addresseeFields.removeClass('hide');
} else if (selected === 'ADD') {
_cache.mailerFields.removeClass('hide');
}
};
return {
init: _init
};
})();
return ClaimsMailingInfo;
});