Archive for 五月, 2011

html禁止选择文字的方法

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ />
<title>测试</title>
</head>
<body>
<div onselectstart=”return false;” style=”-moz-user-select:none;” >你选不了我</div>
</body>
</html>

1 Comment more...

js 实现支持crtl与shift键的行多选

var lastObj = {}; //选中的当前行对象
var tableObj = {}; //表对象

//按键多选
function onTrClick(o) {
tableObj = document.getElementById(“Table1”);
var len = tableObj.rows.length;
for (var i = 1; i < len; i++) { tableObj.rows[i].rowNum = i; } if (event.ctrlKey) {//如果按下了ctrl键 if (o.style.backgroundColor == "#ffffff") { o.style.backgroundColor = '#e3e9f4'; lastObj = o; }else if (o.style.backgroundColor == "#e3e9f4") { o.style.backgroundColor = '#ffffff'; } }else if (event.shiftKey) {//如果按下了shift键 var beginNum, lastNum; if (lastObj.rowNum <= o.rowNum) { beginNum = lastObj.rowNum; lastNum = o.rowNum; }else { beginNum = o.rowNum; lastNum = lastObj.rowNum; } for (var i = 0; i < len; i++) { if (i >= beginNum && i <= lastNum) { tableObj.rows[i].style.backgroundColor = "#e3e9f4"; }else{ tableObj.rows[i].style.backgroundColor = "#ffffff"; } } lastObj = o; }else { for (var i = 1; i < len; i++) { tableObj.rows[i].style.backgroundColor = "#ffffff"; } o.style.backgroundColor = '#e3e9f4'; lastObj = o; } }


Copyright © 1996-2010 Add Lives. All rights reserved.
iDream theme by Templates Next | Powered by WordPress