禁用Fav图标单击在jquery中不起作用

时间:2018-01-31 05:36:25

标签: javascript jquery html

我有两个fa-icon按钮,如加号和删除href标签内的按钮。现在我正在使用模糊检查一列的重复名称,当名称已经退出时,它正常工作我将禁用图标在成功函数中无法点击。名称不存在启用它。它正在为按钮工作但是图标不能正常工作。请帮助我。下面是我尝试过的代码。谢谢提前。

我的HTML

 <div class="txtcbt" style="float:left;width:4%;">
    <a id="add" href="#"><i class="fa fa-plus" style="width:40%;font-size:25px;color:white;background-color:#dc143c;"></i></a>
  </div>

这是启用和禁用不工作的Jquery代码

success:function(response){
        var data = $.parseJSON(response);
          if(data==true){
          //if name is there it showing alert message but disabling is not working
           alert("vendor contact name already exits");
           $('.txtcbt #add .fa fa-plus').prop('disabled', true);
         }else{
            $('.txtcbt #add .fa fa-plus').prop('disabled', false);
         }
      }

3 个答案:

答案 0 :(得分:1)

标签没有禁用属性。 所以在你的css文件中添加它。

<style>
    a.disabled {
       pointer-events: none;
       cursor: default;
    }
        </style>

在您的脚本中执行此操作

success:function(response)
{
    var data = $.parseJSON(response);
    if(data==true)
    {
        //if name is there it showing alert message but disabling is not working
        alert("vendor contact name already exits");
        $('#add').attr('class', 'disabled');
    }
    else
    {
        $('#add').attr('class', '');
    }
}

答案 1 :(得分:0)

我希望这会有所帮助

success:function(response)
{
    var data = $.parseJSON(response);
    if(data==true)
    {
        //if name is there it showing alert message but disabling is not working
        alert("vendor contact name already exits");
        $('#add').attr('disabled', true);
    }
    else
    {
        $('#add').attr('disabled', false);
    }
}

答案 2 :(得分:0)

启用  $(&#39;#add.fa-plus&#39;)。prop(&#39;禁用&#39;,false);

并禁用  $(&#39;#add.fa-plus&#39;)。prop(&#39;禁用&#39;,true);

如果您想从fa-plus更改fa图标。您可以使用 addClass removeClass