有没有人有任何想法我可以做到这一点?我希望我的内容编写者能够将跨度类添加到某些数字量,然后自动超链接到预定义的URL。例如:以编程方式将超链接添加到html中的jquery
And the price at John's hardware shop are<span class="john-shop">$2.35</span>
这可以用php甚至css来完成吗?
感谢您的帮助。
期望的结果:
And the price at John's hardware shop are <a href="http://www.johns-shop.com"><span class="john-shop"> $2.35</span></a>
好了,多试错后,此代码的工作。希望它可以帮助别人。该 “link.js” 包含此代码:
$(document).ready(function() {
$('.john-shop').contents().wrap('<a href="http://www.johns-shop.com"></a>');
});
,这是测试的html:既然你在您的评论指定
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/link.js"></script>
<title></title>
</head>
<body>
And the price at John's hardware shop are<span class="john-shop">$2.35</span>
</body>
</html>
它是确定使用jQuery? – Andrew
您可以添加所需的结果。你想要生成的最后一行代码是什么? – multimediaxp
我可以使用任何工作。增加了预期的结果@EddyXP –