我想要拥有它,以便根据单击的元素中存储的某种引用,单击一个元素会影响另一个元素。我有以下脚本,但它似乎无法正常运行:
$("#elementSelectionList li a").click(function(event) {
var targetElement = $(this).attr('href');
loadEditor($(targetElement));
});
我什至尝试过 loadEditor($('#tagline'));
但它仍然无法正常工作。
这是 HTML
<div id="preview">
<h1 id="tagline" class="editable">The tagline</h1>
</div>
<div id="elementSelectionList">
<ul>
<li><a href="#tagline">Tagline</a></li>
</ul>
</div>
我想要的功能如下:
单击 .editable 元素会使 #textedit 框出现在其前面(有效)。单击 elementSelectionList 列表中的项目应该会使 #textEdit 框出现在具有与 href 对应的 id 的元素前面。
(经过大量编辑)和here is a broader swath of code (由于某种原因,js 现在无法在 fiddle 中正常运行......这只是为了提供更广泛的概述)
最佳答案
您可以使用multiple selector 。您还可以通过链接调用来整理一下。
$(".editable, ui li a[href='#tagline']").not("video, img, textarea")
.click(function(event) {
$("#textEdit").css("display", "none")
.removeAttr("style")
.offset($(this).offset())
.css("display", "block")
.val($(this).text());
});
关于jquery - 如何根据字符串 w id 检索 JQuery 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7116841/