gpt4 book ai didi

javascript - 功能失调的 jQuery 函数在 Chrome 控制台中没有任何线索

转载 作者:行者123 更新时间:2023-11-30 20:25:53 25 4
gpt4 key购买 nike

我有这个功能,我打算用它来禁用满足特定条件的按钮。

<script type="text/javascript" src="Scripts/jquery-1.7.1.min.js"></script>

<script type ="text/javascript">
$(document).ready(function () {

//TEXT BOX 1
$('#<%=txtAmount_VH.ClientID%>').keyup(function (e) {

$vhamnt = $('#<%=txtAmount_VH.ClientID%>').val();
$mxamnt = $('#<%=txtAmount_MX.ClientID%>').val();
$obamnt = $('#<%=txtAmount_OB.ClientID%>').val();
$spamnt = $('#<%=txtAmount_SP.ClientID%>').val();

$totamnt = $('#<%=txtTotalSecurityDeposit.ClientID%>').val();
$sum = $vhamnt + $mxamnt + $obamnt + $spamnt;
if ($sum <= $totamnt) {
$('#<%=btnAddAmount.ClientID %>').attr("disabled", "disabled");
}
});
//TEXT BOX 2
$('#<%=txtAmount_MX.ClientID%>').keyup(function (e) {

$vhamnt = $('#<%=txtAmount_VH.ClientID%>').val();
$mxamnt = $('#<%=txtAmount_MX.ClientID%>').val();
$obamnt = $('#<%=txtAmount_OB.ClientID%>').val();
$spamnt = $('#<%=txtAmount_SP.ClientID%>').val();

$totamnt = $('#<%=txtTotalSecurityDeposit.ClientID%>').val();
$sum = $vhamnt + $mxamnt + $obamnt + $spamnt;
if ($sum <= $totamnt) {
$('#<%=btnAddAmount.ClientID %>').attr("disabled", "disabled");
}
});

//TEXT BOX 3
$('#<%=txtAmount_OB.ClientID%>').keyup(function (e) {

$vhamnt = $('#<%=txtAmount_VH.ClientID%>').val();
$mxamnt = $('#<%=txtAmount_MX.ClientID%>').val();
$obamnt = $('#<%=txtAmount_OB.ClientID%>').val();
$spamnt = $('#<%=txtAmount_SP.ClientID%>').val();

$totamnt = $('#<%=txtTotalSecurityDeposit.ClientID%>').val();
$sum = $vhamnt + $mxamnt + $obamnt + $spamnt;
if ($sum <= $totamnt) {
$('#<%=btnAddAmount.ClientID %>').attr("disabled", "disabled");
}
});

//TEXT BOX 4
$('#<%=txtAmount_SP.ClientID%>').keyup(function (e) {

$vhamnt = $('#<%=txtAmount_VH.ClientID%>').val();
$mxamnt = $('#<%=txtAmount_MX.ClientID%>').val();
$obamnt = $('#<%=txtAmount_OB.ClientID%>').val();
$spamnt = $('#<%=txtAmount_SP.ClientID%>').val();

$totamnt = $('#<%=txtTotalSecurityDeposit.ClientID%>').val();
$sum = $vhamnt + $mxamnt + $obamnt + $spamnt;
if ($sum <= $totamnt) {
$('#<%=btnAddAmount.ClientID %>').attr("disabled", "disabled");
}
});
</script>

另外,控制台也没什么用。

I want the function to disable a button whenever the sum of values for textboxes is larger than another particular textbox. However, that is not happening at all.

我是不是遗漏了一些明显的东西,还是不止于此?

最佳答案

您应该在条件下使用 parseInt 来正确执行此操作,如下所示:

if (parseInt($sum) <= parseInt($totamnt)) {
$('#<%=btnAddAmount.ClientID %>').attr("disabled", "disabled");
}

编辑

您可以用同样的方式检查所有输入。

$('input').keyup(function(e) {

$vhamnt = $('#txtAmount_VH').val();
$mxamnt = $('#txtAmount_MX').val();
$obamnt = $('#txtAmount_OB').val();
$spamnt = $('#txtAmount_SP').val();

$totamnt = $('#txtTotalSecurityDeposit').val();
$sum = $vhamnt + $mxamnt + $obamnt + $spamnt;
if (parseInt($sum) <= parseInt($totamnt)) {
$('#btnAddAmount').attr("disabled", "disabled");
}
});

Online demo (jsFiddle)

编辑 1

这是我检查过的测试标记,它适合我

<div>
<asp:TextBox Class="checkAmount" ID="txtAmount_VH" runat="server" />
<asp:TextBox Class="checkAmount" ID="txtAmount_MX" runat="server" />
<asp:TextBox Class="checkAmount" ID="txtAmount_OB" runat="server" />
<asp:TextBox Class="checkAmount" ID="txtAmount_SP" runat="server" />
<asp:TextBox Class="checkAmount" ID="txtTotalSecurityDeposit" runat="server" />
<asp:Button ID="btnAddAmount" Text="AddAmount" runat="server" />
</div>

<script>
$(document).ready(function() {

$('.checkAmount').keyup(function(e) {

$vhamnt = $('#txtAmount_VH').val();
$mxamnt = $('#txtAmount_MX').val();
$obamnt = $('#txtAmount_OB').val();
$spamnt = $('#txtAmount_SP').val();

$totamnt = $('#txtTotalSecurityDeposit').val();
$sum = $vhamnt + $mxamnt + $obamnt + $spamnt;
if (parseInt($sum) <= parseInt($totamnt)) {
$('#btnAddAmount').attr("disabled", "disabled");
}
});

});
</script>

关于javascript - 功能失调的 jQuery 函数在 Chrome 控制台中没有任何线索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50940842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com