【发布时间】: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