Javascript jQuery:获取链接的html代码
我想不使用正则表达式从div获取html链接 例如:Javascript jQuery:获取链接的html代码,javascript,jquery,hyperlink,Javascript,Jquery,Hyperlink,我想不使用正则表达式从div获取html链接 例如: <div>Please check your links to ensure they point to the correct article.For example, <a href="http://en.wikipedia.org/wiki/Apple">Apple</a> points to the article about the fruit, while <a href="http://
<div>Please check your links to ensure they point to the correct article.For example, <a href="http://en.wikipedia.org/wiki/Apple">Apple</a> points to the article about the fruit, while <a href="http://en.wikipedia.org/wiki/Apple_Inc.">Apple Inc.</a> is the title of the article about the consumer electronics manufacturer. </div>
但是这不起作用。您可以使用
outerHTML
属性映射它,然后加入数组:
var html = $('div').children('a').map(function(){
return this.outerHTML;
}).get().join(' and ');
对于处理多个div,您可以使用:
$('div:has(a)').each(function () {
this.innerHTML = $(this).children('a').map(function () {
return this.outerHTML;
}).get().join(' and ')
});
您可以使用outerHTML
属性映射它,然后加入数组:
var html = $('div').children('a').map(function(){
return this.outerHTML;
}).get().join(' and ');
对于处理多个div,您可以使用:
$('div:has(a)').each(function () {
this.innerHTML = $(this).children('a').map(function () {
return this.outerHTML;
}).get().join(' and ')
});
您可以使用outerHTML
属性映射它,然后加入数组:
var html = $('div').children('a').map(function(){
return this.outerHTML;
}).get().join(' and ');
对于处理多个div,您可以使用:
$('div:has(a)').each(function () {
this.innerHTML = $(this).children('a').map(function () {
return this.outerHTML;
}).get().join(' and ')
});
您可以使用outerHTML
属性映射它,然后加入数组:
var html = $('div').children('a').map(function(){
return this.outerHTML;
}).get().join(' and ');
对于处理多个div,您可以使用:
$('div:has(a)').each(function () {
this.innerHTML = $(this).children('a').map(function () {
return this.outerHTML;
}).get().join(' and ')
});
或从副本:或从副本:或从副本:或从副本: