我需要检查 TextBox 是否具有值,然后将该字段设置为只读。我正在使用 AutoPostBack="false"
,所以我想在后端做这件事是不可能的。
这是我的代码:
Aspx 页面:
<telerik:RadButton runat="server" AutoPostBack="false" CssClass="btnLookup topIngbtnLookup" ID="btnIngredientsLookUp" Image-ImageUrl="~/Images/searchIng.PNG" />
JavaScript:
$('#txtIngredientsName').keypress(function () {
if ($(this).val() != '') {
$(this).addClass('readOnlyFields');
}
else {
$(this).removeClass('readOnlyFields');
}
});
CSS:
.readOnlyFields {
pointer-events: none !important;
background-color: #ccc !important;
}
最佳答案
我认为您正在寻找 enabled
属性。
<script type="text/javascript">
$('#<%=btnIngredientsLookUp.ClientID %>').keypress(function () {
if ($(this).val() !== '') {
$(this).addClass('readOnlyFields');
$(this).attr('enabled', 'false');
} else {
$(this).removeClass('readOnlyFields');
$(this).attr('enabled', 'true');
}
});
</script>
关于jquery - 如果 AutoPostBack ="false",则为 asp.net 文本框设置只读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47495705/