页面小知识点(6)

关键词:javascript、this

<tr>
<th width="25">&nbsp;</th>
<th width="25" align="left">
    <input type="checkbox"  onclick="selectAll(this)">
</th>
<th width="100" nowrap="nowrap" onclick="sort(this)" id="sortCode" >
    <label style="CURSOR:hand">排序序号<span id='sortCode_gif'></span></label>
</th>
<th width="500"  onclick="sort(this)" id="name">
    <label style="CURSOR:hand">产品名称<span id='name_gif'></span></label>
</th>
<th nowrap="nowrap" onclick="sort(this)" id="dept">
    <label style="CURSOR:hand">所属部门<span id='dept_gif'></span></label>
</th>
</tr>
//点击列标题可以实现排序功能
	function sort(sourceObject) {
		document.formQuery.sort.value = sourceObject.id;
		if (document.formQuery.sortType.value == "ASC") {
			document.formQuery.sortType.value = "DESC";
		} else {
			document.formQuery.sortType.value = "ASC";
		}
		query();
	}

说明:

如果点击的是“产品名称”单元格,则函数sort(sourceObject)中, sourceObject.id得到的值就是“name”,

如果点击的是“所属部门”单元格,则sourceObject.id得到的值就是“dept”。

http://huangqiqing123.iteye.com/blog/1451993

猜你喜欢

转载自huangqiqing123.iteye.com/blog/1451993