asp.net<em>标签里的值js怎么获取

&lt;em&gt;a&lt;/em&gt; 在JS里怎么获取a是jquery不是JS 不好意思
2025-01-05 11:20:22
推荐回答(2个)
回答1:

$("#id em").text();
#id是你的上一个标签的id号,那如果上一个标签,我们就找为,这样就可以用$(".em").text();,如果一个网页,只有一个标签,我们就直接用$("em").text()就可以了。
”www.sz886.com“

回答2:

js获取em标签的值:
比如有:Pacific Rim

js代码:

var ems = document.querySelectorAll("em.title");

for (var i = 0; i < ems.length; ++i) {
if (ems[i].querySelector("a") === null) {
var em = ems[i],
text = jQuery(em).text();
var before = text[0] == " ";
var after = text[text.length-1] == " ";
text = text.trim();
while (em.nextSibling && em.nextSibling.className && em.nextSibling.className.indexOf("title") != -1) {
var tmp = em;
em = em.nextSibling;
tmp.parentNode.removeChild(tmp);
text += jQuery(em).text().trim();
++i;
}
var link = text.replace(/[^a-z \-\d']+/gi, "").replace(/\s+/g, "+");
var innerHTML = "" + text + "";
innerHTML = before ? " " + innerHTML: innerHTML;
innerHTML = after ? innerHTML + " " : innerHTML;
ems[i].innerHTML = innerHTML;
}
}