使用Javascript写入非唯一div
我正在为学校构建一个多提要RSS阅读器使用Javascript写入非唯一div,javascript,xml,html,rss,Javascript,Xml,Html,Rss,我正在为学校构建一个多提要RSS阅读器 $("div.theContent").attr("name", "value"); aList是包含每个提要的div(提要的数量会波动) $("div.theContent").attr("name", "value"); title是将用当前提要的属性填充的div。此外,如果单击,它会将当前提要中的属性列表加载到内容中 $("div.theContent").attr("name", "value"); 我想知道在单击标题时如何将属性动态加载到内
$("div.theContent").attr("name", "value");
aList是包含每个提要的div(提要的数量会波动)
$("div.theContent").attr("name", "value");
title是将用当前提要的属性填充的div。此外,如果单击,它会将当前提要中的属性列表加载到内容中
$("div.theContent").attr("name", "value");
我想知道在单击标题时如何将属性动态加载到内容中,因为内容和标题将是非唯一的div(我不能给它们ID)
$("div.theContent").attr("name", "value");
提前感谢您的帮助
$("div.theContent").attr("name", "value");
-Andrewdocument.getElementsByClassName('aList').getElementsByTagName('div')您应该查看用于该操作和其他DOM操作的选择器。差不多
$("div.theContent").attr("name", "value");
通过使用jquery,您可以使用如下代码:
$("div.theContent").attr("name", "value");
$(".theTitle").bind("click", function(){
$el = $(this);
$el.parent().$(".theContent").load('ajax/content.php?news=' . $el.text());
});
这将使您的所有链接都可以点击,一次点击,用ajax/content.php?news=theTitle值更新其相应的content div如果不想更新多个元素,您必须能够确定要更新的元素。如果元素被分组到其他具有“id”值的元素中,您可以利用它。使用一个好的Javascript库,例如或。现在看起来很小,但从长远来看,这些框架为您节省了大量的时间
$("div.theContent").attr("name", "value");
<div class="aList">
<div class="theTitle" onclick="fillContentBox(this)"></div>
<div class="theContent"></div>
</div>
在这两种框架中,您都可以使用以下选项选择该div:
$("div.theContent").attr("name", "value");
$('div.theTitle')
使用jQuery,您可以执行以下操作:
$("div.theContent").attr("name", "value");
$('div.theTitle').click( function() {
var title = $(this).text();
var contentDiv = $(this).siblings('div.theContent');
// Do something with contentDiv and the title
} );
这将使每个标题div都有一个onClick事件,该事件与它关联的content div一起执行某些操作。老实说,如果不使用MooTools之类的库,我很久没有写过这样的代码了。我认为mozilla本机支持GetElementsByCassName,但不支持IE。请查看google上的自定义实现。这里的答案是关于“getElementsByTagName”,而不是类名。IE支持它。getElementsByClassName也在那里吗。。。?这里有一个在IE中工作的getElementsByClassName的js实现。仅供参考:您可以将其缩短为:
$(this).sides('.theContent')代码>或更短:$(this).next('.theContent')代码>
$("div.theContent").attr("name", "value");