作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个asp.net
webform,我希望禁用我的提交按钮,如果我的 asp:TextBox
为空,并且也没有为我的 asp:RadioButton
进行选择.
目前我的领域有以下内容,但我不知道如何加入单选按钮
JQuery
$(document).ready(function ()
{
$("#MainContent_btnRemoveUser").prop('disabled', true);
$("#MainContent_btnAddUser").prop('disabled', true);
});
// Disables 'Remove' button unless all fields popluted
$("#MainContent_txtRemoveUser").on("change", function ()
{
if ($('#MainContent_txtUsername').val())
{
$("#MainContent_btnRemoveUser").prop('disabled', false);
}
else
{
$("#MainContent_btnRemoveUser").prop('disabled', true);
}
});
HTML
<div class="form-group">
<asp:Label runat="server" AssociatedControlID="txtRemoveUser" CssClass="col-sm-offset-2 col-sm-3 control-label">Enter Name To Be Removed</asp:Label>
<div class="col-sm-3">
<asp:TextBox runat="server" ID="txtRemoveUser" CssClass="form-control" />
</div>
</div>
<div class="form-group">
<asp:Label runat="server" CssClass="col-sm-offset-2 col-sm-3 control-label">
<b>Request For</b>
</asp:Label>
<div class="col-sm-3">
<label class="radio-inline">
<asp:RadioButton runat="server" ID="rbRemoveYourself" GroupName="RemoveRequestFor" /> Myself
</label>
<label class="radio-inline">
<asp:RadioButton runat="server" ID="rbRemoveOtherUser" GroupName="RemoveRequestFor" /> Other user
</label>
</div>
</div>
<div class="row">
<div class="col-sm-offset-8 col-sm-3" style="padding-left: 0px">
<asp:Button ID="btnRemoveUser" runat="server" Text="Remove From The List" CssClass="btn btn-danger" ToolTip="Click to remove the specified user from the payday lunch list." />
</div>
</div>
最佳答案
给你!添加了一个新函数来禁用该按钮,并将在文本框模糊和单选按钮更改时调用。
HTML
<div class="form-group">
<asp:Label runat="server" AssociatedControlID="txtRemoveUser" CssClass="col-sm-offset-2 col-sm-3 control-label">Enter Name To Be Removed</asp:Label>
<div class="col-sm-3">
<asp:TextBox runat="server" ID="txtRemoveUser" CssClass="form-control" />
</div>
</div>
<div class="form-group">
<asp:Label runat="server" CssClass="col-sm-offset-2 col-sm-3 control-label">
<b>Request For</b>
</asp:Label>
<div class="col-sm-3">
<label class="radio-inline">
<asp:RadioButton runat="server" ID="rbRemoveYourself" GroupName="RemoveRequestFor" /> Myself
</label>
<label class="radio-inline">
<asp:RadioButton runat="server" ID="rbRemoveOtherUser" GroupName="RemoveRequestFor" /> Other user
</label>
</div>
</div>
<div class="row">
<div class="col-sm-offset-8 col-sm-3" style="padding-left: 0px">
<asp:Button ID="btnRemoveUser" runat="server" Text="Remove From The List" CssClass="btn btn-danger" ToolTip="Click to remove the specified user from the payday lunch list." />
</div>
</div>
JavaScript
<script>
$(document).ready(function () {
$("#MainContent_btnRemoveUser").prop('disabled', true);
$("#MainContent_btnAddUser").prop('disabled', true);
});
$("#MainContent_txtRemoveUser").on("blur", function () {
disableButton();
});
$("#MainContent_rbRemoveYourself").change(function () {
disableButton();
});
$("#MainContent_rbRemoveOtherUser").change(function () {
disableButton();
});
// Disables 'Remove' button unless all fields popluted
function disableButton() {
var isRbRemoveSelfChecked = $("#MainContent_rbRemoveYourself").is(':checked')
var isRbRemoveOtherChecked = $("#MainContent_rbRemoveOtherUser").is(':checked')
if ($('#MainContent_txtRemoveUser').val() != '' && (isRbRemoveSelfChecked || isRbRemoveOtherChecked)) {
$("#MainContent_btnRemoveUser").prop('disabled', false);
}
else {
$("#MainContent_btnRemoveUser").prop('disabled', true);
}
}
</script>
关于javascript - 当 asp :TextBox Empty & no asp:RadioButton Is Selected 时禁用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33478736/
我是一名优秀的程序员,十分优秀!