Javascript 使用唯一选择器关闭所有打开的醉酒工具提示

Javascript 使用唯一选择器关闭所有打开的醉酒工具提示,javascript,jquery,html,css,animation,Javascript,Jquery,Html,Css,Animation,在我的项目中,我使用jquery tipsy工具提示来验证表单的字段。 我想一次隐藏所有打开的工具提示,而不必指定每个元素的id,但不幸的是我不能。 我试过这种方法,但是按钮hide2和hide3不能正常工作 <p><input type="text" name="name" id="name" rel="ttp" /></p> <p><input type="text" name="sname" id="sname" rel="ttp" /

在我的项目中,我使用jquery tipsy工具提示来验证表单的字段。 我想一次隐藏所有打开的工具提示,而不必指定每个元素的id,但不幸的是我不能。 我试过这种方法,但是按钮hide2和hide3不能正常工作

<p><input type="text" name="name" id="name" rel="ttp" /></p>
<p><input type="text" name="sname" id="sname" rel="ttp" /></p>
<p><input type="text" name="email" id="email" rel="ttp" /></p>

<input type="button" value="show" id="show_ttp">
<input type="button" value="hide" id="hide_ttp">
<input type="button" value="hide2" id="hide2_ttp">
<input type="button" value="hide3" id="hide3_ttp">


我怎么办?谢谢你

我不知道如何使用这个工具提示插件,但是你可以使用强制隐藏这些对象

由于tipsy插件使用其隐藏方法删除其对象,因此您也可以使用jQuery
.remove()
函数,不要忘记tipsy会用javascript附加对象,所以请使用
$(document).on
来操作它们。选中此项:

编辑:要隐藏所有打开的工具提示,请使用此功能:


我想这就是你要找的

  $("#hide3_ttp").click(function(){
        $('[rel=ttp]').each(function(index, element){$(element).tipsy('hide');});
    });

只需将所有元素包装在div/form/span中,并更改以下代码:

$("#hide2_ttp").click(function(){
    $('*').tipsy('hide');
});

其中“elements”是输入包装器的id

通过这种方式,您可以拥有多组输入并分别关闭它们的醉酒状态


FIDDLE:

要隐藏所有醉酒的工具提示,只需使用.tipsy类作为选择器,并使用jquery
hide()

代码:

$("#hide2_ttp").click(function(){
    $('.tipsy').hide();
});

谢谢,但我必须一次将所有工具提示隐藏在唯一的selector@PaoloRossi再次检查我的答案,因为tipsy插件使用其
隐藏
方法删除其对象,所以您也可以使用jQuery
.remove()
函数,并且不要忘记tipsy使用
javascript
附加对象,所以使用
$(文档).on
来操纵它们。非常干净。这正是我想要的。谢谢。@PaoloRossi很高兴能帮助你,朋友我感觉像
$('.tipsy')。删除()
甚至更干净,因为如果你多次显示和隐藏它们,它不会污染你的
DOM
。谢谢你的建议,但是@Kamesh的代码看起来更干净
  $("#hide3_ttp").click(function(){
        $('[rel=ttp]').each(function(index, element){$(element).tipsy('hide');});
    });
$("#hide2_ttp").click(function(){
    $('*').tipsy('hide');
});
$("#hide2_ttp").click(function(){

 $('#elements input').each(function(){
        $(this).tipsy('hide');
    });
});
$("#hide2_ttp").click(function(){
    $('.tipsy').hide();
});