有沒有人有任何想法我可以做到這一點?我希望我的內容編寫者能夠將跨度類添加到某些數字量,然後自動超鏈接到預定義的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 –