这是项目里本来有的js
<script type='text/javascript'>var IsCheckDateOfCtrId=''; $(function() { SetCheckEmptyJS(); });function SetCheckEmptyJS () { $('#txtName').focusout(function () { if ($('#txtName').val() == '') { $('#txtName').attr('class', 'RequiredWarningTextBoxBorderStyle'); } else { $('#txtName').attr('class', 'tbox'); } ClearLblError(); }); $('#txtAddress').focusout(function () { if ($('#txtAddress').val() == '') { $('#txtAddress').attr('class', 'RequiredWarningTextBoxBorderStyle'); } else { $('#txtAddress').attr('class', 'tbox'); } ClearLblError(); }); $('#txtCorp').focusout(function () { if ($('#txtCorp').val() == '') { $('#txtCorp').attr('class', 'RequiredWarningTextBoxBorderStyle'); } else { $('#txtCorp').attr('class', 'tbox'); } ClearLblError(); }); $('#txtContact').focusout(function () { if ($('#txtContact').val() == '') { $('#txtContact').attr('class', 'RequiredWarningTextBoxBorderStyle'); } else { $('#txtContact').attr('class', 'tbox'); } ClearLblError(); }); $('#txtDesScale').focusout(function () { if ($('#txtDesScale').val() == '') { $('#txtDesScale').attr('class', 'RequiredWarningTextBoxBorderStyle'); } else { $('#txtDesScale').attr('class', 'tbox'); } ClearLblError(); }); $('#txtFacilities').focusout(function () { if ($('#txtFacilities').val() == '') { $('#txtFacilities').attr('class', 'RequiredWarningTextBoxBorderStyle'); } else { $('#txtFacilities').attr('class', 'tbox'); } ClearLblError(); }); $('#ddlCateagory').change(function () { if ($(this).val() == '') { $('#sp_ddlCateagory').attr('class', 'RequiredWarningDropDownListBorderStyle'); } else { $('#sp_ddlCateagory').attr('class', ''); } ClearLblError(); }); $('#btnAdd').click(function () { if ($('#txtName').val() == '') { $('#txtName').attr('class', 'RequiredWarningTextBoxBorderStyle'); ClearLblError(); } else { $('#txtName').attr('class', 'tbox'); } ClearLblError(); if ($('#txtAddress').val() == '') { $('#txtAddress').attr('class', 'RequiredWarningTextBoxBorderStyle'); ClearLblError(); } else { $('#txtAddress').attr('class', 'tbox'); } ClearLblError(); if ($('#txtCorp').val() == '') { $('#txtCorp').attr('class', 'RequiredWarningTextBoxBorderStyle'); ClearLblError(); } else { $('#txtCorp').attr('class', 'tbox'); } ClearLblError(); if ($('#txtContact').val() == '') { $('#txtContact').attr('class', 'RequiredWarningTextBoxBorderStyle'); ClearLblError(); } else { $('#txtContact').attr('class', 'tbox'); } ClearLblError(); if ($('#txtDesScale').val() == '') { $('#txtDesScale').attr('class', 'RequiredWarningTextBoxBorderStyle'); ClearLblError(); } else { $('#txtDesScale').attr('class', 'tbox'); } ClearLblError(); if ($('#txtFacilities').val() == '') { $('#txtFacilities').attr('class', 'RequiredWarningTextBoxBorderStyle'); ClearLblError(); } else { $('#txtFacilities').attr('class', 'tbox'); } ClearLblError(); if ($('#ddlCateagory').val() == '') { $('#sp_ddlCateagory').attr('class', 'RequiredWarningDropDownListBorderStyle'); ClearLblError(); } else { $('#sp_ddlCateagory').attr('class', ''); } ClearLblError(); }); $('#btnEdit').click(function () { if ($('#txtName').val() == '') { $('#txtName').attr('class', 'RequiredWarningTextBoxBorderStyle'); ClearLblError(); } else { $('#txtName').attr('class', 'tbox'); } ClearLblError(); if ($('#txtAddress').val() == '') { $('#txtAddress').attr('class', 'RequiredWarningTextBoxBorderStyle'); ClearLblError(); } else { $('#txtAddress').attr('class', 'tbox'); } ClearLblError(); if ($('#txtCorp').val() == '') { $('#txtCorp').attr('class', 'RequiredWarningTextBoxBorderStyle'); ClearLblError(); } else { $('#txtCorp').attr('class', 'tbox'); } ClearLblError(); if ($('#txtContact').val() == '') { $('#txtContact').attr('class', 'RequiredWarningTextBoxBorderStyle'); ClearLblError(); } else { $('#txtContact').attr('class', 'tbox'); } ClearLblError(); if ($('#txtDesScale').val() == '') { $('#txtDesScale').attr('class', 'RequiredWarningTextBoxBorderStyle'); ClearLblError(); } else { $('#txtDesScale').attr('class', 'tbox'); } ClearLblError(); if ($('#txtFacilities').val() == '') { $('#txtFacilities').attr('class', 'RequiredWarningTextBoxBorderStyle'); ClearLblError(); } else { $('#txtFacilities').attr('class', 'tbox'); } ClearLblError(); if ($('#ddlCateagory').val() == '') { $('#sp_ddlCateagory').attr('class', 'RequiredWarningDropDownListBorderStyle'); ClearLblError(); } else { $('#sp_ddlCateagory').attr('class', ''); } ClearLblError(); }); }; function ClearLblError() { if(document.getElementById('lblError')!=null) { document.getElementById('lblError').innerText = ''; } } </script>
现在ddlcategory的值不是空判断,而是-1,我在页面上得怎么添加
?
😄
同上
ctrl + F 找到所有关于ddlCateagory的事件绑定,一个一个改
关于ddl绑定的话,既然你用js写的,就用js获取,并赋值,可以给一个隐藏的控件,后台在获取,并绑定