解决方案 »
- 如何获得下个月一共多少天呢
- jquery或者js获取鼠标放到图片上的坐标(相对的)
- 关于传递 xmlhttprequest 的问题
- HTML中,一个textbox的内容改变后,离开焦点,然后另外一个textbox的内容变成一样的,在线等,急
- javascript中换行连接符是什么?
- innerHTML的问题?高手看看!
- 为什么我的定义的js只能直接放在head区,而不可以用调用的方法使用?
- 求一篇刷屏代码!
- 帮我看看这句script语句错在那里呀,老报undefined为空???
- 怎样在HTML下取浏览器地址(用JavaScript 别的也行)
- 做web打印时,如何让用户能够拖放,改变字体大小等?
- 新手请教
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title><script type="text/javascript">
var now="";
var text="";
var tds=[];
function createDom(tagName,value,num){
var dom=document.createElement(tagName);
if(!value){
}else if(typeof(value)=='string'||typeof(value)=='number'){
dom.innerHTML=value;
}else if(value.tagName){
dom.appendChild(value);
}
if(tagName=='td'){
dom.setAttribute('num',num);
tds.push(dom);
dom.onclick=function(){
clearTdStyle()
this.style.backgroundColor='red';
text.value=value;
now=this;
}
}
return dom;
}
function clearTdStyle(){
for(var i=0;i<tds.length;i++){
tds[i].style.backgroundColor='white';
}
}
function setTdStyle(dom){
clearTdStyle();
text.value=dom.innerHTML;
dom.style.backgroundColor='red';
now=dom;
window.setTimeout(function(){dom.focus()},200);
}
function init(){
var table=document.getElementById("tb");
var tbody=createDom('tbody');
text=document.getElementById("show");
for(var i=0;i<=50;i++){
tbody.appendChild(createDom('tr',createDom('td','这是第'+i+"行",i)));
}
table.appendChild(tbody);
}
window.onload=init;
document.onkeydown=function(e){
var a=e||window.event;
var key=a.keyCode;
var num=parseInt(now.getAttribute('num'));
if(key==38){
if(num>0){
setTdStyle(tds[num-1]);
}
}else if(key==40){
if(num<tds.length-1){
setTdStyle(tds[num+1]);
}
}
}
</script>
</head>
<body>
<input type="text" id="show" value="do">
<table id="tb">
</table>
<body>
</body>
</html>
不很明白你的意思
if (event.keyCode == 38) return false;
}只能向下滚 IE7测试通过