【问题标题】:Enable effect when button disable按钮禁用时启用效果
【发布时间】:2015-04-21 09:36:53
【问题描述】:

我在女巫上有一个禁用按钮,我想在鼠标悬停时设置一个效果,所以我有这个代码:

$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 function 之后,他将获取拥有className 的所有元素并在mouse pass hover 元素时打印popUp

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 时事件悬停停止。我该怎么做才能让它发挥作用。

【问题讨论】:

标签: javascript jquery html css


【解决方案1】:

能否更新你的代码以使用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>

【讨论】:

  • 嗯,是的,但这不是我想要的,我想打印一个弹出窗口,但很好,allu 的链接解释得很好。
【解决方案2】:

你可以试试下面的代码。

$('.className').on('mouseenter',function(e){
   callMyFunction();
});

【讨论】:

    猜你喜欢
    • 2016-08-31
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-07
    • 1970-01-01
    • 2017-01-03
    相关资源
    最近更新 更多