jQuery教程

jquery 找到文章中内容,替换并加链接

本文主要是介绍jquery 找到文章中内容,替换并加链接,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-type" content="text/html;charset=utf-8"/>
		<title></title>
		
		<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
		<link href="jquery-ui/css/base/jquery-ui-1.9.2.custom.css" rel="stylesheet">
		<script src="jquery-ui/js/jquery-1.8.3.js"></script>
		<script src="jquery-ui/js/jquery-ui-1.9.2.custom.js"></script>
		
		
		<style type="text/css">
			
		</style>
	</head>
	<body>
		<center>
			
			<input type="button" id="btn" value="包装"/>
			<div id="div1">
				<p>jquery</p>
				<p>百度是一家公司</p>
				<p>360 这里也有一个百度</p>
			</div>
			
		</center>
		<script type="text/javascript">
			$(function(){
				$("#btn").click(function(){
					if($("p:contains('百度')").length>0){
							
						var a=$("p:contains('百度')")[0];
							var txt=$(a).text();
							var txt2=txt.replace('百度',"<a href='http://www.baidu.com'>百度</a>");
							$(a).html(txt2);
						
					}
					
					
				});
			})
		</script>
	</body>
</html>
这篇关于jquery 找到文章中内容,替换并加链接的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!