问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

急,我想用网页实现如图的操作~javascript(dom操作)

发布网友 发布时间:2022-04-07 09:27

我来回答

3个回答

热心网友 时间:2022-04-07 10:56

IE7,FireFox3.0运行成功

<html>
<head>
<title></title>
<style type="text/css">
#d0 {background-color:#ccc;width:55%;height:55%}
table {margin:2%;border:solid blue 1px;width:95%;height:95%;background-color:#139E9B}
td {border:solid blue 1px;padding:1px;}
.d1 {background:#0200FC;width:100%;height:50%;font-size:0px}
.d2 {background:#FCFF85;width:100%;height:50%;font-size:0px}
</style>
<script type="text/javascript">
var myTd = document.getElementsByTagName("td");
var selectedTd = myTd[0];
function init() {
for(i=0; i<myTd.length; i++) {
myTd[i].selected = false;
myTd[i].divHeight = 50;
}
}
function setMark(obj) {
for(i=0; i<myTd.length; i++) {
if(myTd[i].selected == true) {
myTd[i].selected = false;
break;
}
}
obj.selected = true;
}
function changeHeight(e) {
var j;
var m = document.getElementsByTagName("tr").length;
var n = myTd.length;
var x = n/m;
if(e.keyCode)
keycode = e.keyCode;
else
keycode = e.which;
for(i=0; i<n; i++) {
if(myTd[i].selected == true) {
selectedTd = myTd[i];
j = i;
break;
}
}
if(keycode == 107) {
if(selectedTd.divHeight > 0) {
selectedTd.divHeight -= 10;
myHeight = selectedTd.divHeight+"%";
selectedTd.firstChild.style.height = myHeight;
myHeight = 100 - selectedTd.divHeight;
myHeight = myHeight+"%";
selectedTd.lastChild.style.height = myHeight;
}
} else if(keycode == 109) {
if(selectedTd.divHeight < 100) {
selectedTd.divHeight += 10;
myHeight = selectedTd.divHeight+"%";
selectedTd.firstChild.style.height = myHeight;
myHeight = 100 - selectedTd.divHeight;
myHeight = myHeight+"%";
selectedTd.lastChild.style.height = myHeight;
}
} else {
switch(keycode)
{
case 37: //向左
if(j%x == 0) {
myTd[j].selected = false;
myTd[j-1+x].selected =true;
} else {
myTd[j].selected = false;
myTd[j-1].selected =true;
}
break;
case 38: //向上键
if(j < x) {
myTd[j].selected = false;
myTd[j+x*(m-1)].selected =true;
} else {
myTd[j].selected = false;
myTd[j-x].selected =true;
}
break;
case 39: //右键
if((j+1)%x == 0) {
myTd[j].selected = false;
myTd[j+1-x].selected =true;
} else {
myTd[j].selected = false;
myTd[j+1].selected =true;
}
break;
case 40: //向下键
if(j >= (n-x)) {
myTd[j].selected = false;
myTd[j-x*(m-1)].selected =true;
} else {
myTd[j].selected = false;
myTd[j+x].selected =true;
}
break;
default:
break;
}

}
}
</script>
</head>
<body onKeyDown="changeHeight(event);" onload="init();">
<div id="d0">
<table cellspacing="7px">
<tr>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
</tr>
<tr>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
</tr>
<tr>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
<td onMousedown="setMark(this);"><div class="d1"></div><div class="d2"></div></td>
</tr>
</table>
</div>
</body>
</html>

热心网友 时间:2022-04-07 12:14

table.js:
// JavaScript Document
(function(){
//需定义每行表格数量
ctn = 16;
//定义左右两个层的ID
var leftdiv = document.getElementById('left');
var rightdiv = document.getElementById('right');
//左层主表格
var t = leftdiv.getElementsByTagName('table');
var tl = t.length;
//右侧附属表格
var tson = rightdiv.getElementsByTagName('table');
var tsonl = tson.length;
//检测两边是否相等
if(tl!=tsonl){alert('主副表内表格数量不等!');return;}
//当前表格、上表格、下表格、按键
// + = 187; - = 189; l = 37; u = 38; r = 39; d = 40;
var v = ''
var up = '',sonup = '';
var dn = '',sondn = '';
var key = '';
//记录当前位置
var vid = 0;
var vsid = 0;
//遍历
for(i=0;i<tl;i++){
var cur=t[i];
cur.onclick = function(){var n=this; return getcur(n);};
tson[i].onclick = function(){alert('附表无法选择');}
}
function getcur(obj){
var e = obj;
e.className = 'sel';
//清空其他表格的样式
for(i=0;i<tl;i++){
if(t[i]!=e){t[i].className='';}else{vid=i;vsid=i;/*获取当前表格的位置*/}
}
//获取上下两个表格
var td = e.getElementsByTagName('td');
var tdl = td.length;
var tdson = tson[vsid].getElementsByTagName('td');

for(i=0;i<tdl;i++){
if(td[i].className=='y'){
dn = td[i];
sondn = tdson[i];
}
else{
up = td[i];
sonup = tdson[i];
}
}
v = e;
//为up和dn添加height
dn.style.height = '100';
up.style.height = '100';
sondn.style.height = '100';
sonup.style.height = '100';
}
//键盘事件
document.onkeydown = function(){
key=event.keyCode;
switch(key){
case 187:
add();break;
case 189:
dec();break;
case 37:
l();break;
case 38:
u();break;
case 39:
r();break;
case 40:
d();break;
default : break;
}
}
//操作
function add(){
if(v){
//初始化色彩
up.style.background = '#ffffff';
dn.style.background = '#ffff00';
v.style.background = '';
var uh = parseInt(up.style.height.toString());
var dh = parseInt(dn.style.height.toString());
uh = uh - 10;
dh = dh + 10;
if(uh<1){uh=1;dh=dh-1;}
//执行
up.style.height = uh.toString();
dn.style.height = dh.toString();
sonup.style.height = uh.toString();
sondn.style.height = dh.toString();
}
else{
alert('please select a table');
}
}

function dec(){
if(v){
//初始化色彩
up.style.background = '#ffffff';
dn.style.background = '#ffff00';
v.style.background = '';
var uh = parseInt(up.style.height.toString());
var dh = parseInt(dn.style.height.toString());
uh = uh + 10;
dh = dh - 10;
if(dh<1){dh=1;uh=uh-1;}
//执行
up.style.height = uh.toString();
dn.style.height = dh.toString();
sonup.style.height = uh.toString();
sondn.style.height = dh.toString();
}
else{
alert('please select a table');
}
}

function l(){
var g = vid - 1;
if(g>=0){
v = t[g];
vid = g;
getcur(v);
}
}

function r(){
var g = vid + 1;
if(g<=(tl-1)){
v = t[g];
vid = g;
getcur(v);
}
}

function u(){
var g = vid - ctn + 1;
if(g>=0){
v = t[g];
vid = g;
getcur(v);
}
}

function d(){
var g = vid + ctn - 1;
if(g<=(tl-1)){
v = t[g];
vid = g;
getcur(v);
}
}

})();

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
*{margin:0;padding:0;}
div{width:300px; float:left;margin-right:10px;}
.clear{clear:both;}
table{float:left; margin-bottom:6px;width:18px; margin-right:2px; border:#ccc 1px solid; cursor:hand;}
td{height:100px; line-height:1px;}
.y{background-color:#FFFF00;}
.sel{border:#ff0000 1px solid;}
</style>
</head>

<body>
<div class="clear"></div>
<div id="left">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td class="y"> </td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td class="y"> </td>
</tr>
</table>
</div>

<div id='right'>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td class="y"> </td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td class="y"> </td>
</tr>
</table>
</div>
<script type="text/javascript" src="table.js"></script>
</body>
</html>

热心网友 时间:2022-04-07 13:49

<!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>
<title> ldh_web_editor </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="mfx.css" rel="stylesheet" type="text/css">
<script src="mfx.js"></script>
<style>
body{background:#fff}
.google{height:100px;float:left;border:2px solid #000; }
.google th{font-size:0px;overflow:hidden;width:20px}
.google .up{background:#0500FC;height:50%; }
.google .down{background:#FCFF85;height:50% }
.google.selected{border:2px dashed red;}
</style>
</head>
<body>
<table id="googleBox">
<tr>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
</tr>
<tr>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
</tr>
<tr>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
<td><table class="google"><tr><th class="up"> </th></tr><tr><th class="down"> </th></tr></table></td>
</tr>
</table>
</body>
<script language="javascript">
CSS = function(el) {
return el.currentStyle || document.defaultView.getComputedStyle(el, null);
};
var box=document.getElementById("googleBox");
var tables=box.getElementsByTagName("TABLE");
for (var i=0;i<tables.length;++i ) {
var el=tables[i];
el.onfocus=new Function("this.className='google selected';window.focusTable=this");
el.onblur=new Function("this.className='google';window.focusTable=null");
};
setHeight=function (nav){
var th=window.focusTable.getElementsByTagName("TH");
var old=parseInt(CSS(th[1]).height);
var New=Math.max(0,Math.min(100,old+10*nav));
th[1].style.height=New+'%';
th[0].style.height=(100-New)+'%';
th[0].style.display=New==100?'none':'';
th[1].style.display=New==0?'none':'';
};
move=function (td,a,b){
var x=td.cellIndex,y=td.parentNode.rowIndex;
var pos=[x+a,y+b];
try{
td2=box.rows[pos[1]].cells[pos[0]].getElementsByTagName("TABLE")[0];
td2.focus();
}catch(e){};
};
document.onkeyup=function (e){
if(window.focusTable==null)return;
var key=(e||event).keyCode;
var nav=false;
var td=focusTable.parentNode;
switch (key){
case 187:return setHeight(1);
case 189:return setHeight(-1);
case 37:return move(td,-1,0);
case 38:return move(td,0,-1);
case 39:return move(td,1,0);
case 40:return move(td,0,1);
}
}
</script>
</html>
代码很简洁
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
vivox9和x9i有什么区别 ...设置原则跟构造要求。构造柱的设置原则跟构造要求是什么_百度... ...的U型钢筋锚环要几道?在哪里可以找到依据啊 ...月末不含税库存金额1065000元,请计算门店库存天数 公蟹吃什么 公蟹吃什么东西 爬行健身操功能和原理 锻炼爬行的好处有哪些呢 爬行健身法有什么优缺点 檀木如何粘合 成田剑先生还为哪些日本动漫配音,有名一点滴。谢谢了,大神帮忙啊 请问大佬有MeinPlatz(硬盘空间扫描工具)V7.11 中文安装版软件免费百度云资源吗 AMD 5000开四核超3.2G默认电压1.432V正常吗? 目前最新版的gta5是V几? 我的是V5 那里可以找到网络图片下载免费软件 DNF无敌V1.32 V1.33 请问大佬有WinLogOnView(登陆日志查看器) V1.33 绿色版软件百度云资源吗 浩辰cad怎么把标注字体旋转关闭 牛奶和鸡蛋一起吃好不好 求助,哪位朋友有泡泡卫星网络电视 V1.33的用户名和注册码啊,谢谢了 跪拜击破英语单词v1.33免注册版 小学生的营养餐牛奶和鸡蛋先吃什么好? 求魔兽冰封《冥皇* v1.33 正式版》最强武器怎么合成..谢谢! 鸡蛋和牛奶怎么做出好吃的鸡蛋羹 请问大佬有UninstallView(程序卸载工具) V1.33 英文绿色版软件免费百度云资源吗 牛奶,鸡蛋一天中何时吃最好? GTA5版本: R组完美补丁(全dlc)v1.33升级档。 打开游戏后显视 需重启,要连接网际网 鸡蛋和牛奶应怎么吃? 为什么笔记本开机realtek pcie fe family controller series v1.33 鸡蛋和牛奶怎么吃最补? 请问有卡吧工具箱 V1.33软件免费百度云资源吗 买富国沪深300怎么样?投资富国基金是否安全? 我想选择一个定投沪深300的 不知道选择哪个 富国量化沪深300 国富沪深 嘉实沪深 哪个好点 请问大家比如说富国沪深300,嘉实沪深300,都一样的基金沪深300,有什么不一样吗? 富国沪深300怎么样 富国沪深300和大成沪深300定投3年,每月500元,哪个的收益好些,也可以推荐点其他的指数型的,谢谢各位大师 富国沪深300的卖点是啥,有专业人士回答下吗? 基金定投组合;富国天惠、富国沪深、富国中证2013年8月,如何 新基富国沪深300基本面精选值得买吗? 容易宝300对接的基金产品是天弘沪深300指数基金吗 《外星人就在月球背面》的作者李卫东 全国有多少叫李东卫的 富国沪深300指数为什么比嘉实沪深300指数基金跌得厉害 山东嘉誉企业管理咨询服务有限公司怎么样? 我现在打算月定投1000的基金,投资大约在5年左右,目前选择了一直富国沪深300增强指数基金,请问这只如何 社会工程学攻击的原理是什么? 济南嘉誉企业管理咨询有限公司怎么样? 社会工程学是什么 李东卫是大家说的衡水狗吗 无锡匡威变压器有限公司怎么样? 中创普惠(天津)网络科技有限公司怎么样?