[英]What's the easiest way to anchor some text to an external link using jQuery?
inside my HTML page I add some text using this: 在我的HTML页面内,我使用以下代码添加一些文本:
<script>
$('.description').text('my description')
</script>
Inside my description
I need to place an anchor tag href to an external link like this: <a href="http://link_to_website.com">link to a website</a>
在
my description
我需要将锚标记href放置到这样的外部链接: <a href="http://link_to_website.com">link to a website</a>
How could I proceed using jQuery to achieve something like this? 我怎样才能继续使用jQuery来实现这样的目标?
You might need to do this: 您可能需要这样做:
$('.description').text('my description').append($('<a />', {href:"http://linkofhref", text:"text goes here."}));
Check the demo below: 查看下面的演示:
$('.description').text('my description ').append($('<a />', {href:"http://linkofhref", text:"text goes here."}));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class='description'></div>
try this.. 尝试这个..
<script>
$(document).ready(function(){
$('.description').html('<a href="http://link_to_website.com">link to a website</a>');
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.