zl程序教程

您现在的位置是:首页 >  前端

当前栏目

jQuery如何追加内容?匿名函数

jQuery 如何 函数 内容 匿名 追加
2023-09-14 08:58:24 时间
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
	*{margin:0;padding:0;}
	</style>
	<script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript">
	$(function(){
		$('div').html(function(index,value){//通过匿名函数赋值,并传递index
			return value +'<em>www.taobao.com</em>'//追加<em>的内容

		});
	});
	</script>
</head>
<body>
<div title="11"><strong>www.baidu.com</strong></div>
<div title="22"><strong>www.baidu.com</strong></div>
<div title="33"><strong>www.baidu.com</strong></div>
	
</body>
</html>

这样写拓展性比较好~~~  

如图显示: