我有以下字符串:
var content = '<a href="www.topSecret.com">Link</a>'
我的主要目标是:
var content = '<span>Link</span>'
或者,如果不可能,至少:
var content = '<a href="" >Link</a>'
一些注意事项:
- 这个 var 将被发送到 PHP 变量,所以如果使用 PHP 更容易,它也被接受
- jQuery 最受欢迎
感谢您的所有帮助!
我有以下字符串:
var content = '<a href="www.topSecret.com">Link</a>'
我的主要目标是:
var content = '<span>Link</span>'
或者,如果不可能,至少:
var content = '<a href="" >Link</a>'
一些注意事项:
感谢您的所有帮助!
使用 PHP 轻松完成strip_tags()
:
$str = '<a href="www.topSecret.com">Link</a>';
$result = '<span>' . strip_tags( $str) . '</span>';
echo $result;
输出:
<span>Link</span>
var $content = $('<a href="www.topSecret.com">Link</a>');
var result = "<span>" + $content.text() + "</span>";
var input = '<a href="www.topSecret.com">Link</a>';
pattern = /<a.+>(.*?)<\/a>/;
matches = input.match(pattern);
result = '<span>' + matches[1] + '</span>';
alert(result);
这是工作示例:http: //jsbin.com/oqikib/1/edit