我在女巫身上有一个禁用按钮,我想在鼠标悬停时产生效果,为此我有这段代码:
$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/