我正在尝试将所选的选择应用于表单中的所有选择元素。
这是我的JS文件 script.js ,其中定义了应用所选方法
var script = (function(jQuery,window){
var applyChosen = function()
{
jQuery('#saveForm :input').each(function(){
if(jQuery(this).is('select'))
{
var id = jQuery(this).attr('id');
console.log('Applying chosen to id '+id);
jQuery('#saveForm').find('#'+id).chosen({
allow_single_deselect : true
});
}
});
};
return {
applyChosen : applyChosen
};
})(jQuery,window);
这是我的 HTML 文件,我在其中调用applyChosen()方法,将所选文件应用于所有选择字段。
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery-ui.js"></script>
<script type="text/javascript" src="Chosen/chosen.jquery.js"></script>
<link rel="stylesheet" href="Chosen/chosen.css">
<link rel="stylesheet" href="jquery-ui.css">
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
script.applyChosen();
});
</script>
</head>
<body>
<form name="mainform" id="saveForm" action="file:///C:/">
<!--##GENERAL##-->
<div id="fromuser">
<table width="100%" id="userTable">
<tr><td class="title-cell" colspan="2"><p class="title">ERD Reporting</p></td></tr>
<tr>
<td class="label-cell">* Report Type :</td>
<td>
<select id="repcode" name="repcode" class="validate[required] widthpx" data-prompt-position="inline">
<option VALUE=""></option>
<option VALUE="All Reports">All Reports</option>
<option VALUE="004">004 - GMAC Branch 004</Option>
<option VALUE="005">005 - GMAC Branch 005</Option>
<option VALUE="007">007 - GMAC Branch 007</Option>
<option VALUE="008">008 - GMAC Branch 008</Option>
<option VALUE="010">010 - GMAC Branch 010</Option>
<option VALUE="020">020 - GMAC Branch 020</Option>
<option VALUE="021">021 - GMAC Branch 021</Option>
<option VALUE="023">023 - GMAC Branch 023</Option>
<option VALUE="029">029 - GMAC Branch 029</Option>
<option VALUE="045">045 - GMAC Branch 045</Option>
<option VALUE="061">061 - GMAC Branch 061</Option>
<option VALUE="084">084 - GMAC Branch 084</Option>
<option VALUE="085">085 - GMAC Branch 085</Option>
<option VALUE="103">103 - GMAC Branch 103</Option>
<option VALUE="123">123 - GMAC Branch 123</Option>
<option VALUE="154">154 - GMAC Branch 154</Option>
<option VALUE="201">201 - GMAC Branch 201</Option>
<option VALUE="340">340 - GMAC Branch 340</Option>
<option VALUE="ACK">ACK - ACH File Receipt Acknowledgement</Option>
<option VALUE="ADJ">ADJ - Adjustment Report</Option>
</select>
</td>
</tr>
<tr id="accountRowID">
<td class="label-cell" >* Account Number :</td>
<td>
<select name="anumber" id="anumber" class="validate[required] widthpx" data-prompt-position="inline" onChange="script.selectChange(this);" title="You can select all accounts or enter your complete Account Number exactly as on site.Use comma [,] as a separator for multiple accounts">
<option value=""></option>
<option value="All Accounts">All Accounts</option>
<option value="customAccountNumbers">Enter Account Number</option>
</select>
</td>
</tr>
<tr id="PrinterNameRow">
<td class="label-cell">Printer Name :</td>
<td>
<select name="printtodefault" id="printtodefault" class="validate[required] widthpx" data-prompt-position="inline">
<option value="false">--None--</option>
<option value="true">--Default--</option>
<option value="Send_To_One_Note_2013">Send To One Note 2013</option>
<option value="Microsoft_XPS_Document_Writer">Microsoft XPS Document Writer</option>
<option value="Microsoft_Print_to_PDF">Microsoft Print to PDF</option>
<option value="Fax">Fax</option>
</select>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
此代码适用于除IE8以外的所有浏览器。 我应该做些什么改变才能使它在IE8 +浏览器上运行?