什么'这是使用jQuery将一些文本锚定到外部链接的最简单方法
What's the easiest way to anchor some text to an external link using jQuery?
在我的HTML页面中,我使用以下内容添加了一些文本:
<script>
$('.description').text('my description')
</script>
在my description
内部,我需要放置一个指向外部链接的锚标记href,如下所示:<a href="http://link_to_website.com">link to a website</a>
我如何使用jQuery来实现这样的目标?
您可能需要这样做:
$('.description').text('my description').append($('<a />', {href:"http://linkofhref", text:"text goes here."}));
查看下面的演示:
$('.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>
试试这个。。
<script>
$(document).ready(function(){
$('.description').html('<a href="http://link_to_website.com">link to a website</a>');
});
</script>
use.html()
$('.description').html('<a href="http://link_to_website.com">link to a website</a>')
或
$('.description').html('my description <br> <a href="http://link_to_website.com">link to a website</a>')
相关文章:
- 如何在外部文档中使用javascript将文本区域的内容保存为变量
- jQuery对请求图像的外部文本进行查询
- 什么'这是使用jQuery将一些文本锚定到外部链接的最简单方法
- 将外部文本从.txt加载到html文件
- 通过外部锚点输入值时的文本区域行计数
- 点击谷歌图表栏显示外部文本文件的内容
- InternetExplorer:外部文本文件只能使用二进制格式
- 使用外部 javascript 更改多个表格单元格中的文本
- 从外部HTML文档中获取文本
- 替换 jquery 加载的外部 html 文件中的文本
- 加载外部页面并替换文本
- 无法获取动态添加的文本区域的外部 HTML/值
- 什么正则表达式模式将从包含的外部HTML文本中提取内部HTML
- 在网页上显示来自 TXT、HTML 等(托管在云上)的外部文本
- 当隐藏输入框的文本被外部 jquery 更改时,如何触发函数
- 将文本片段从外部页面获取到谷歌浏览器扩展程序
- 债权人 - 将外部样式表应用于 CKEditor 文本区域中的内部文本
- 如何在Wordpress Fancybox图像上将文本超链接到外部网站
- Javascript 从外部网页获取文本
- 将外部纯文本内容读入字符串