我正在使用jQuery的onchange event of select box
。 在更改时,我在其他div中给出了display property = none
。 问题是,当我从数据库获取数据并将其设置在选择框中时,onchange
属性未应用于给定值。为什么? 我的代码Onchange事件选择框
<select id="patientType" name="Patient_Type">
<option value="">--SELECT--</option>
<option value="OPD">OPD</option>
<option value="IPD">IPD</option>
</select>
<div id="roomInfo" clasas="inactive"></div>
脚本
$('#patientType').change(function() {
if ($('#patientType').val() == 'IPD') {
if ($('#roomInfo').hasClass('inactive')) {
$('#roomInfo').removeClass('inactive');// CSS Property Display None in this class
$('#roomInfo').addClass('active');
}
} else {
if ($('#roomInfo').hasClass('active')) {
$('#roomInfo').removeClass('active');
$('#roomInfo').addClass('inactive');
}
}
});
现在,我得到的数据从数据库并设置该选择patientType $( '#patientType')VAL(数据从数据库中获取)。 不能申请onchange事件适用,不能显示我的roomInfo div 所以有可能与否。 或另一种获取该方法的方法。 请帮忙。 提前致谢。
请向我们显示您的代码 –
如何从数据库中提取数据?它是ajax还是页面加载? –