禁用 if...else 上的按钮

马特·德雷克

我有一些 JQuery,如果返回特定结果,我想用它来禁用 php 页面上的按钮。

查询

...
success:function(data){
            $("#value10").html(data.price);
            $("#total").html(data.newtotal);
            $("#toohigh").html(data.toohigh);
            if(data.toohigh === 1) {
                $("#subbut").attr('disabled', 'disabled');
            } else if(data.toohigh === 0){
                $("#subbut").attr('disabled', 'disabled');
            }

php

<button type="submit" name="Submit" class="btn btn-primary align-content-center" id="subbut">

我尝试了各种不同的可能解决方案,但没有一个在data.toohigh等于 1时禁用按钮

我错过了什么?

法埃马扎兹·巴内吉

它是由您的变量data.toohigh与您的条件10数据类型不匹配引起的

试试这个代码

...
success:function(data){
            $("#value10").html(data.price);
            $("#total").html(data.newtotal);
            $("#toohigh").html(data.toohigh);
            if(data.toohigh == '1') {
                $("#subbut").attr('disabled', 'disabled');
            } else if(data.toohigh == '0'){
                $("#subbut").attr('disabled', 'disabled');
            }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章