【发布时间】:2014-07-18 21:54:58
【问题描述】:
我正在尝试根据我单击的链接加载具有不同内容的 div...
虽然当我单击它时它似乎适用于第一个链接,但单击其他链接只会将内容替换为 'encodeMe' 的相同内容,但我已经为 'htmlize-me' 指定了要替换的不同内容'
第一次运行时我没有使用 jQuery 的 .bind() 函数。我只是使用 .click() ,两者的结果相同。查看 jQuery API,我认为使用 .bind() 函数会将其中的每个函数绑定到该特定页面元素,但它似乎将其应用于我的所有链接。
我已经使用 .hide 和 .show 来切换 div 实现了相同的效果,但我想更优雅地了解如何做到这一点,这是我尝试过的替代方案...
这是相关的html:
<label for="list-root">App Hardening</label>
<input type="checkbox" id="list-root" />
<ol>
<li id="encode-me"><a class="show-popup" href="#">encodeMe()</a></li>
<li id="htmlize-me"><a class="show-popup" href="#">htmlizeMe()</a></li>
</ol>
<div class="overlay-bg">
<div class="overlay-content">
<div class="the-content"></div>
<br><button class="close-button">Close</button>
</div>
</div>
这是我为触发内容更改而编写的脚本:
$('#encode-me').bind('click' , function() {
$('div.the-content').replaceWith('<h3 style="color: #008ccc;"> function encodeMe( string ) </h3>' +
'Found in <p>[web root]/redacted/redacted.asp</p>');
});
});
$('#htmlize-me').bind('click' , function() {
$('div.the-content').replaceWith('Hi, Im something different');
});
});
【问题讨论】:
标签: javascript jquery html css