首页 > 代码库 > jQuery Easy UI Tooptip(提示框)组件

jQuery Easy UI Tooptip(提示框)组件

我们都知道DOM节点的title属性,Tooptip组件就是比较强大的title,它可以自由的设置自己的样式、位置以及有自己相关的触发事件。

示例:

<!DOCTYPE html>
<html>
<head>
<title>jQuery Easy UI</title>
<meta charset="UTF-8" />
<script type="text/javascript" src=http://www.mamicode.com/"easyui/jquery.min.js"></script>>网上看到一个比较好的例子:

<!DOCTYPE html>
<html>
<head>
<title>jQuery Easy UI</title>
<meta charset="UTF-8" />
<script type="text/javascript" src="easyui/jquery.min.js"></script>
<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js" ></script>
<link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css" />
<script>
	$(function () {
		var data = [
			{A:'name1',B:150,C:135,D:285,E:97},
			{A:'name2',B:59,C:96,D:155,E:167},
			{A:'name3',B:83,C:86,D:169,E:53},
			{A:'name4',B:66,C:61,D:127,E:158}
		];
		$('#dg').datagrid({
			columns:[[
				{field:'A',title:'A',width:100,formatter:formatA},
				{field:'B',title:'B',width:100},
				{field:'C',title:'C',width:100},
				{field:'D',title:'D',width:100}
			]],
			data: data,
			onLoadSuccess:function(){
				createTooltip();
			}
		});

		function formatA(value,row,index){
			return '<span data-p1='+index+' class="easyui-tooltip">' + value + '</span>';
		}
		function createTooltip(){
			$('#dg').datagrid('getPanel').find('.easyui-tooltip').each(function(){
				var index = parseInt($(this).attr('data-p1'));
				$(this).tooltip({
					content: $('<div></div>'),
					onUpdate: function(cc){
						var row = $('#dg').datagrid('getRows')[index];
						var content = '<div>content</div><ul>';
						content += '<li>name: '+row.A+'</li>';
						content += '<li>B: '+row.B+'</li>';
						content += '<li>C: '+row.C+'</li>';
						content += '<li>D: '+row.D+'</li>';
						content += '</ul>';
						cc.panel({
							width:200,
							content:content
						});
					},
					position:'right'
				});
			});
		}

	})
</script>
</head>
<body>
  	<table id="dg" style="width:400px;height:200px"></table>
</body>
</html>
执行效果:


点击下载源代码

jQuery Easy UI Tooptip(提示框)组件