jQuery replaceAll()函数
我想用一个输入框替换每个链接,输入框的值是链接的URL。我想使用jQuery replaceAll()函数。标准格式为jQuery replaceAll()函数,jquery,Jquery,我想用一个输入框替换每个链接,输入框的值是链接的URL。我想使用jQuery replaceAll()函数。标准格式为 $(content).replaceAll(target); 我的问题是:如何引用目标对象?换句话说,在下面的代码中,我应该用什么替换当前链接 $('').attr('value',TheCurrentLink.href}).replaceAll($('a'); 您需要执行以下操作: $('a').each(function(){ var $a = $(this);
$(content).replaceAll(target);
我的问题是:如何引用目标对象?换句话说,在下面的代码中,我应该用什么替换当前链接
$('').attr('value',TheCurrentLink.href}).replaceAll($('a');
您需要执行以下操作:
$('a').each(function(){
var $a = $(this);
$a.replaceWith($('<input/>').attr('value', $a.attr('href')));
});
$('a')。每个(函数(){
var$a=$(本);
$a.replaceWith($('').attr('value',$a.attr('href'));
});
您需要执行以下操作:
$('a').each(function(){
var $a = $(this);
$a.replaceWith($('<input/>').attr('value', $a.attr('href')));
});
$('a')。每个(函数(){
var$a=$(本);
$a.replaceWith($('').attr('value',$a.attr('href'));
});
我会使用replaceWith()
:
$('a').each(function(){
$(this).replaceWith('<input type="text" value="' + $(this).attr('href') + '" />');
});
$('a')。每个(函数(){
$(此)。替换为(“”);
});
工作示例:
工作示例2添加了将输入转换回链接的逻辑:我将使用replaceWith()
:
$('a').each(function(){
$(this).replaceWith('<input type="text" value="' + $(this).attr('href') + '" />');
});
$('a')。每个(函数(){
$(此)。替换为(“”);
});
工作示例:
工作示例2,添加了将输入转换回链接的逻辑:尝试:
$("a").replaceWith(function() {
return "<input type='text' value='"+$(this).attr("href")+"' />";
});
$(“a”).replaceWith(函数(){
返回“”;
});
测试。尝试:
$("a").replaceWith(function() {
return "<input type='text' value='"+$(this).attr("href")+"' />";
});
$(“a”).replaceWith(函数(){
返回“”;
});
测试