仅在表单中鼠标悬停在图像上时的 JQuery 工具提示

发布于 2024-12-02 01:16:22 字数 4971 浏览 0 评论 0原文

我在这里有一个例子 http://www.kriesi.at/archives/create-simple-tooltips-with-css-and-jquery/comment-page-2#comment-2746

它创建了一个样式表中的效果并屏蔽通过此函数传递的任何标记的默认工具提示,

     $(document).ready(function() {


         simple_tooltip("img","tooltip"); 


        });

        function simple_tooltip(target_items, name){
        $(target_items).each(function(i){
        $("body").append("<div class='"+name+"' type='img' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");

        var my_tooltip = $("#"+name+i);

        $(this).removeAttr("title").mouseover(function(){
                my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
        }).mousemove(function(kmouse){
                my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
        }).mouseout(function(){
                my_tooltip.fadeOut(400);
        });
    });
}

但问题是它在页面的每个图像标记上显示工具提示,因为我只想在表单验证帮助图标上显示它。这是我的表格

    <form id="form1">

        <table id="tblSignUp" border="0" cellpadding="2" cellspacing="5"
            style="border: 0px solid black; color: #FFFFFF;">
            <div id="inputs">
            <tr>
                <td>First Name<font class="AsterikLabel">*</font> :</td>
                <td><input id="firstname" size="35" maxlength="50" type="text"
                     style="width: 175px;"
                     onblur="checkError(this);" name="fname" />
                  <img  title="Alphabets, numbers and space(' ') , no special characters min 3 and max 20 characters." 
                src="PsychOImages/20.png" align="bottom" /></td>
                <td id="firstName1"></td>
            </tr>
            <tr>
                <td>Last Name<font class="AsterikLabel">*</font> :</td>
                <td><input type="text" id="lastname" style="width: 175px;"
                     name="lastname"
                     onblur="checkError(this);" />
                  <img  title="Alphabets, numbers and space(' ') , no special characters min 3 and max 20 characters." 
                    src="PsychOImages/20.png" align="bottom" />
                                                                  </td>
                <td id="lastname1"></td>
            </tr>
            <tr>
                <td>Email<font class="AsterikLabel">*</font> :</td>
                <td><input id="email" type="text" style="width: 175px;"
                     name="email"
                    onblur="checkError(this);" />
                  <img title=" The Email address format is [email protected]."  src="PsychOImages/20.png" align="bottom" /></td>
                <td id="email1"></td>
            </tr>
            <tr>
                <td>Telephone<font class="AsterikLabel">*</font> :</td>
                <td><input id="phone" type="text" style="width: 175px;"
                     name="phone"
                    onblur="checkError(this);" maxlength="16"/>
                  <img title="Format : 339-4248 or (095) 2569835 or +7 (095)1452389" 
                    src="PsychOImages/20.png" align="bottom" /></td>
                <td id="phone1"></td>
            </tr>
            <tr>
                <td>Choose a Password<font class="AsterikLabel">*</font> :</td>
                <td><input id="password" type="password" style="width: 175px;"

                    name="password" onblur="checkError(this);" />
                  <img title="Password feild can only contains 7 to 15 characters" src="PsychOImages/20.png" align="bottom" /></td>
                <td id="password1"></td>
            </tr>
            <tr>
                <td>Re-Type Password<font class="AsterikLabel">*</font> :</td>
                <td><input id="repassword" type="password"
                    style="width: 175px;" 
                     name="retype" onblur="checkError(this);" />
                 <img title="Retype teh password same as above for confirmation" src="PsychOImages/20.png" align="bottom" /></td>
                <td id="repassword1"></td>
            </tr>
</div>
        </table>
        </form>


i have tried putting my form into a div and then giving that Div id to the function
`simple_tooltip("","")`   but it stops working then.... please help!  

i got an example here at http://www.kriesi.at/archives/create-simple-tooltips-with-css-and-jquery/comment-page-2#comment-2746

it creates a effect in style sheet and masks the default tooltip of any tag that is passed through this function

     $(document).ready(function() {


         simple_tooltip("img","tooltip"); 


        });

        function simple_tooltip(target_items, name){
        $(target_items).each(function(i){
        $("body").append("<div class='"+name+"' type='img' id='"+name+i+"'><p>"+$(this).attr('title')+"</p></div>");

        var my_tooltip = $("#"+name+i);

        $(this).removeAttr("title").mouseover(function(){
                my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
        }).mousemove(function(kmouse){
                my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
        }).mouseout(function(){
                my_tooltip.fadeOut(400);
        });
    });
}

but the problem is it shows tooltip on each an every image tag of the page where as i only wanted to show it on form validation help icon. here is my form

    <form id="form1">

        <table id="tblSignUp" border="0" cellpadding="2" cellspacing="5"
            style="border: 0px solid black; color: #FFFFFF;">
            <div id="inputs">
            <tr>
                <td>First Name<font class="AsterikLabel">*</font> :</td>
                <td><input id="firstname" size="35" maxlength="50" type="text"
                     style="width: 175px;"
                     onblur="checkError(this);" name="fname" />
                  <img  title="Alphabets, numbers and space(' ') , no special characters min 3 and max 20 characters." 
                src="PsychOImages/20.png" align="bottom" /></td>
                <td id="firstName1"></td>
            </tr>
            <tr>
                <td>Last Name<font class="AsterikLabel">*</font> :</td>
                <td><input type="text" id="lastname" style="width: 175px;"
                     name="lastname"
                     onblur="checkError(this);" />
                  <img  title="Alphabets, numbers and space(' ') , no special characters min 3 and max 20 characters." 
                    src="PsychOImages/20.png" align="bottom" />
                                                                  </td>
                <td id="lastname1"></td>
            </tr>
            <tr>
                <td>Email<font class="AsterikLabel">*</font> :</td>
                <td><input id="email" type="text" style="width: 175px;"
                     name="email"
                    onblur="checkError(this);" />
                  <img title=" The Email address format is [email protected]."  src="PsychOImages/20.png" align="bottom" /></td>
                <td id="email1"></td>
            </tr>
            <tr>
                <td>Telephone<font class="AsterikLabel">*</font> :</td>
                <td><input id="phone" type="text" style="width: 175px;"
                     name="phone"
                    onblur="checkError(this);" maxlength="16"/>
                  <img title="Format : 339-4248 or (095) 2569835 or +7 (095)1452389" 
                    src="PsychOImages/20.png" align="bottom" /></td>
                <td id="phone1"></td>
            </tr>
            <tr>
                <td>Choose a Password<font class="AsterikLabel">*</font> :</td>
                <td><input id="password" type="password" style="width: 175px;"

                    name="password" onblur="checkError(this);" />
                  <img title="Password feild can only contains 7 to 15 characters" src="PsychOImages/20.png" align="bottom" /></td>
                <td id="password1"></td>
            </tr>
            <tr>
                <td>Re-Type Password<font class="AsterikLabel">*</font> :</td>
                <td><input id="repassword" type="password"
                    style="width: 175px;" 
                     name="retype" onblur="checkError(this);" />
                 <img title="Retype teh password same as above for confirmation" src="PsychOImages/20.png" align="bottom" /></td>
                <td id="repassword1"></td>
            </tr>
</div>
        </table>
        </form>


i have tried putting my form into a div and then giving that Div id to the function
`simple_tooltip("","")`   but it stops working then.... please help!  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

活泼老夫 2024-12-09 01:16:22
$(function() {
    simple_tooltip("#form1 img", "tooltip");
});

simple_tooltip 函数的第一个参数是一个选择器,因此您可以使用它来查找所需的任何元素。

另外,您必须删除

(以及相应的

)标记,因为您的 html 无效。您不能div直接放入table元素内。

$(function() {
    simple_tooltip("#form1 img", "tooltip");
});

First argument of the simple_tooltip function is a selector so you can use it to find any elements you want to.

Also, You have to remove the <div id="inputs"> (and corresponding </div>) tag because your html isn't valid. You can't put a div directly inside the table element.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文