javascript - 禁用按钮时启用效果

标签 javascript jquery html css

我在女巫身上有一个禁用按钮,我想在鼠标悬停时产生效果,为此我有这段代码:

$commentAddTimeshitForbiden = AddPopupJQ("Button disable");
echo "<input type='button' value='Validate' $commentAddTimeshitForbiden/>";

AddPopupJQ 只是一个函数,它允许将一个类添加到我的输入中,并且标题跟在参数中给出的文本之后。

function AddPopupJQ($text='', $title='')
{
   return "class='popupjq' data-popupjq_text='" . htmlspecialchars(stripslashes($text), ENT_QUOTES | ENT_HTML401, "ISO-8859-15") . "' data-popupjq_title='" . htmlspecialchars(stripslashes($title), ENT_QUOTES | ENT_HTML401, "ISO-8859-15") . "'";
}

在我有一个 jquery 函数 之后,它将获取所有具有 className 的元素并在 鼠标时打印一个 popUp传递 hover 元素。

function popupJQ() {
   $(".popupjq").each(function(index) {
      //Récuperation des données/paramètres
      var title = ($(this).data('popupjq_title')) ? $(this).data('popupjq_title') : '';
      var text = ($(this).data('popupjq_text')) ? $(this).data('popupjq_text') : '';
      //Pour l'accessibilité, on ajoute la balise Alt aux images
      if ($(this).is("img")) {
         var sep = (title && text) ? " : " : "";
         $(this).attr("alt", title + sep + text);
      }
      //Création de la tooltip
      var txt = "";
      if (title)
         txt += "<B><FONT class='tooltitle'>" + title + "</FONT></B><br>";
      if (text)
         txt += "<FONT class='tooltext'>" + text + "</FONT>";
      if(txt){
         $(this).tooltipster({
             content: $(txt),
             position: 'bottom-left',
             delay: 100,
             debug: false,
             speed: 0
         });
      }
   });   
}

问题是它在按钮启用时有效,但在禁用时无效。 我认为这是因为当按钮为 disable 时事件悬停停止。我该怎么做才能让它发挥作用。

最佳答案

能否更新一下代码,使用css来实现,如下:

<html>
<head>
    <style>
        input:hover:disabled {
            background-color: red;
        }
    </style>

</head>

<body>
    <input type="button" value="Disabled" disabled/>    
    <input type="button" value="Enabled"/>  
</body>

关于javascript - 禁用按钮时启用效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29768338/

相关文章:

javascript - 当页面包含 asp.net ajax updatepanel 时,css 链接悬停和 javascript 不工作

javascript - jQuery 分区可见性隐藏不起作用

javascript - jQuery 宽度 (%) 不会在 windowResize 上停止计算?

JavaScript 文件无法与 servlet 一起正常工作

html - 无法将图像居中

javascript - AngularJs 自定义指令未与 "textarea"绑定(bind)

JavaScript 和复选框

javascript - 从 JSON.parse 访问值

javascript - 单击后将 html 对象传递给函数?

html - Vim:按需更改语法突出显示