jQuery简单操作

    jQuery简单操作  


一:简介

      

        在前端方面一直很小白、只了解一些基本的JS、还不是太熟悉、jQuery也是、用的时候有时候很简单的用法还要去查、系统的学习一下、把常用的记录一下做个备忘、也是笔记。不断更新。。。

 

二:常用函数

 

        1、$(‘#id’).remove()——移除id为id的元素。

        2、$(‘#id’).empty()—— 移除id为id的元素中的内容。

        3、$(‘#id’).show()—— 显示id为id的元素中的内容。

        4、$(‘#id’).hide()—— 隐藏id为id的元素中的内容。

 

三:实用插件

 

        1、table中合并相同内容的单元格:

                a)       内容:

	//封装的一个JQuery小插件、实现相同内容合并单元格的代码
	jQuery.fn.rowspan = function(colIdx) {
		return this.each(function() {
			var that;
			$('tr', this).each(
					function(row) {
						$('td:eq(' + colIdx + ')', this).filter(':visible').each(
								function(col) {
									if (that != null
											&& $(this).html() == $(that).html()) {
										rowspan = $(that).attr("rowSpan");
										if (rowspan == undefined) {
											$(that).attr("rowSpan", 1);
											rowspan = $(that).attr("rowSpan");
										}
										rowspan = Number(rowspan) + 1;
										$(that).attr("rowSpan", rowspan);
										$(this).hide();
									} else {
										that = this;
									}
								});
					});
		});
	}


                b)       测试内容:动态生成数据table、页面和js:

<body οnlοad="init();">
	<div align="center">
		<table id="logDetailTable" width="99%" border="1" collapse="collapse">
		<thead>
			<tr>
				<th width="20%" height="40px">项目名称</th>
				<th width="20%" height="40px">监控类型</th>
				<th width="35%" height="40px">子项目名</th>
				<th width="25%" height="40px">日志信息</th>
			</tr>
		</thead>
		<tbody id="logDetailInfo">

		</tbody>
	</table>
	</div>
	
</body>
function init(){
	//获取数据集result
	...
	//构建table:
	for (var i in result){
		fillShowLogTable(result[i]);
	}
	
	//指定要合并的table的那些行
	$('#logDetailTable').rowspan(0);
	$('#logDetailTable').rowspan(1);
}

function fillShowLogTable(list){
	var str = '';
	str += '<tr><td style="width:20%;text-align:center">'+list.PRO_TITLE+'</td>';
	str += '<td style="width:20%;height:30px;text-align:center">'+list.SUB_PROJECT_NAME+'</td>';
	str += '<td style="width:35%;height:30px;text-align:center">'+list.TASK_NAME+'</td>';
		
	if(list.TIP_VALUE == 'no'){
		list.TIP_VALUE = '无新日志';
		str += '<td class="noNewLog" style="width:25%;height:30px;text-align:center">'+list.TIP_VALUE+'</td></tr>';
	}else if(list.TIP_VALUE == 'yes'){
		list.TIP_VALUE = '有新日志';
		str += '<td class="hasNewLog" style="width:25%;height:30px;text-align:center">'+list.TIP_VALUE+'</td></tr>';
	}
	$(str).appendTo($('#logDetailInfo'));
}


                c)       测试效果:

 


总结:

 

       学以致用。实践是最快的捷径!



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值