我想用一个输入框替换每个链接,输入框的值是链接的URL。我想使用jQuery replaceAll()函数。标准格式是
$(content).replaceAll(target);我的问题是:如何引用目标对象?换句话说,在下面的代码中,我应该用什么替换TheCurrentLink?
$('<input>').attr('value', TheCurrentLink.href}).replaceAll($("a"));发布于 2011-07-23 22:56:56
你需要做更像这样的事情:
$('a').each(function(){
var $a = $(this);
$a.replaceWith($('<input/>').attr('value', $a.attr('href')));
});发布于 2011-07-23 23:14:06
尝试:
$("a").replaceWith(function() {
return "<input type='text' value='"+$(this).attr("href")+"' />";
});测试这里。
发布于 2011-07-23 22:57:50
我会使用replaceWith()来代替:
$('a').each(function(){
$(this).replaceWith('<input type="text" value="' + $(this).attr('href') + '" />');
});工作示例:http://jsfiddle.net/AlienWebguy/6KP4H/
工作示例2,添加了将输入转换回链接的逻辑:http://jsfiddle.net/AlienWebguy/6KP4H/1/
https://stackoverflow.com/questions/6803795
复制相似问题