简体   繁体   English

php 中动态创建的按钮的禁用属性不会使用 jquery 中的名称或 ID 更改,但它的 css 属性正在更改

[英]The disabled attribute of a dynamically created button in php not changing using it's name or id in jquery but it's css property is changing

None of the commented statement are working but the uncommented one is working perfectly fine评论的声明都没有工作,但未评论的声明工作得很好

echo "<div class='col-xs-12 col-sm-3 emphasis'>
                    <button class='btn btn-primary btn-block disabled' name = 'proceed' id= 'proceed'><span class='fa fa-user'></span> Proceed </button>
                </div> "  //This is dynamically generated button using php


  $('[name="proceed"').css('background-color','black');
                            // $('[name="proceed"]').removeAttr('disabled');
                            // $('[name="proceed"]').attr('disabled',false);
                            // $('[name="proceed"]').prop("disabled",false);
                            //$('#proceed').prop("disabled",false);
                            //$('#proceed').attr('disabled',false);
                            // $('#proceed').removeAttr('disabled');

You're trying to set attribute disabled while it's class name您正在尝试将属性设置为disabled ,而它的名称为 class

You need either set disabled as attribute or use removeClass function您需要将disabled设置为属性或使用removeClass function

 $('[name="proceed"').css('background-color','black'); $('[name="proceed"]').removeClass('disabled'); // $('[name="proceed"]').attr('disabled',false); // $('[name="proceed"]').prop("disabled",false); //$('#proceed').prop("disabled",false); //$('#proceed').attr('disabled',false); // $('#proceed').removeAttr('disabled');
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class='col-xs-12 col-sm-3 emphasis'> <button class='btn btn-primary btn-block disabled' name = 'proceed' id= 'proceed'><span class='fa fa-user'></span> Proceed </button> </div>

Try the following:尝试以下操作:

$('button[name="proceed"]').css('background-color','black');

EDIT:编辑:

Disabling input :禁用输入

$("#proceed").prop('disabled', true);


Enabling Input :启用输入

$("#proceed").prop('disabled', false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM