【问题标题】:How to call different var strings for jquery tooltip inside function如何在函数内为jquery工具提示调用不同的var字符串
【发布时间】:2012-08-19 05:50:15
【问题描述】:

我想在同一个函数中创建多个字符串,并使这段代码在整个网站上更有用。

我的 JS 代码如下所示:

    function() {$(".tool-tip-wrapper").click(function () {
      $(".tool-tip",this).html("<img src='/images/ui-elements-sprite.png' class='top-arrow'><p>This is string one.</p><div class='close'></div>").toggle('fast');
    });

我的 html 代码如下所示:

<div class="tool-tip-wrapper"> click me
    <div class="tool-tip"></div>
</div>

【问题讨论】:

  • 它的可变部分是什么?
  • “同一个函数中有多个字符串”是什么意思?
  • .html 之后我想添加类似 tooltipone ("I am tooltip one") tooltiptwo ("I am tooltip two") tooltipthree ("I am tooltip three") 之类的字符串
  • 或者我怎样才能为不同的字符串创建不同的函数并从 html 调用?对不起,我是新手!
  • 我认为我非常接近但有语法错误。我在父函数中创建了 2 个函数。每个函数都有自己的字符串并使用点击函数:function() { $(".tool-tip-wrapper").click( function bestBet () { $(".tool-tip",this).html("I am string one").toggle('fast'); }; function shobi () { $(".tool-tip",this).html("I am string two").toggle('fast'); }; };

标签: javascript jquery xhtml tooltip


【解决方案1】:

下面的标记将解决问题。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js" language="javascript"></script>
<script type="text/javascript">

$(document).ready(function(){

    $(".tool-tip-wrapper").click(function(){
                                                $(".tool-tip",this).html("<p>"+this.title+"</p><div class='close'></div>").toggle('fast');
                                           });
});
</script>   
</head>

<body>
<div class="tool-tip-wrapper" title="This is string one.">
    click me
    <div class="tool-tip"></div>
</div>
</body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-05
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    • 2013-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多