根据FileUpload的值,控制textBox的可用与否

JS代码:

<script type="text/javascript">
$(document).ready(function ()
{
$("#<%= masterFileUpload.ClientID %>").change(function ()
{
if ($("#<%= masterFileUpload.ClientID %>").val() != "")
{
$("#<%=txtMasterFilePwd.ClientID%>").removeAttr("disabled", "disabled");
}
else
{
$("#<%=txtMasterFilePwd.ClientID%>").val("");
$("#<%=txtMasterFilePwd.ClientID%>").attr("disabled", "disabled"); 
}
});

});
</script>

HTML代码:

 1  <tr>
 2                     <td style="text-align: right" class="auto-style1">**文件名:</td>
 3                     <td class="auto-style2">
 4                         <asp:FileUpload ID="masterFileUpload" runat="server" ClientIDMode="Static" Width="350" />
 5                     </td>
 6                     <td class="auto-style2">
 7                         <asp:Label ID="lbmasterFileUpload" runat="server" ClientIDMode="Static"></asp:Label>
 8                     </td>
 9                 </tr>
10                 <tr>
11                     <td style="text-align: right" class="auto-style1">**密码:</td>
12                     <td class="auto-style2">
13                         <asp:TextBox ID="txtMasterFilePwd" runat="server" CssClass="txt_search" ClientIDMode="Static" Width="200px" onkeydown="if(event.keyCode==222){return false;}"  ></asp:TextBox>
14                     </td>
15                 </tr>

说明: <asp:TextBox ID="txtMasterFilePwd"。。。。>是服务器控件,但是在JS中设置它的属性时,一定要用编译后生成的对应HTML控件的属性才好用。

原文地址:https://www.cnblogs.com/gates/p/3465128.html