当点击左上的按钮,按钮颜色改变,且提示为左上
解决方案 »
- 用JS播放视频时,显示加载的进度
- 求助,一个JS获取最上端URL的问题。
- 提取ASP记录,调用JS方法
- 用了javascript,鼠标老是闪烁,有沒有解决办法?
- 正则表达匹配html标签问题【急急急】
- 为防止重复提交.按钮变灰了,但 CGI脚本读取不到值(在线等)
- 当我对一个层进行left,top进行重新定位时问题出现一个类似爆炸的动画出现,怎么回事,是病毒吗?害得看不到程序执行的正常结果!
- 如何判定checkbox的问题!
- genuis(不死鸟)领分,谢谢你的回答!
- 请问是在什么地方设置,可以达到这样的效果
- 今天小弟做了一个网站上线了,请大家多找BUG,在下感激不尽,谢谢了!
- 求一个JS!能用上下键操作table
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>test</title>
<style>
.up {}
.down {background-color:black;}
</style>
<script>
function btnClick(obj){
for(var i=1;i<=9;i++){
document.getElementById("btn"+i).className = "up";
}
obj.className = "down";
var arr = ["左上","上","右上","左","中","右","左下","下","右下"];
var index = obj.id.substring(3,4);
document.getElementById("span1").innerText = arr[parseInt(index,10)-1];
}
</script>
</head><body>
位置:<span id="span1"></span><br>
<input type="button" value="" id="btn1" onclick="btnClick(this)">
<input type="button" value="" id="btn2" onclick="btnClick(this)">
<input type="button" value="" id="btn3" onclick="btnClick(this)">
<br>
<input type="button" value="" id="btn4" onclick="btnClick(this)">
<input type="button" value="" id="btn5" onclick="btnClick(this)">
<input type="button" value="" id="btn6" onclick="btnClick(this)">
<br>
<input type="button" value="" id="btn7" onclick="btnClick(this)">
<input type="button" value="" id="btn8" onclick="btnClick(this)">
<input type="button" value="" id="btn9" onclick="btnClick(this)">
</body></html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="JavaScript">
function showzs(){
document.addr.address.value="左上";
}
function shows(){
document.addr.address.value="上";
}
function showys(){
document.addr.address.value="右上";
}
function showz(){
document.addr.address.value="左";
}
function showc(){
document.addr.address.value="中";
}
function showy(){
document.addr.address.value="右";
}
function showzx(){
document.addr.address.value="左下";
}
function showx(){
document.addr.address.value="下";
}
function showyx(){
document.addr.address.value="右下";
}</script>
</head><body>
<form name="addr">
位置:<input type="text" name="address" value="" style="width:50"><br>
<input type="button" name="左上" style="width:25;height:25" value="\" onClick="showzs()" onMouseOut="this.style.background='#FFFFFF'" onMouseOver="this.style.background='red'">
<input type="button" name="上" style="width:25;height:25" value="|" onClick="shows()" onMouseOut="this.style.background='#FFFFFF'" onMouseOver="this.style.background='red'">
<input type="button" name="右上" style="width:25;height:25" value="/" onClick="showys()" onMouseOut="this.style.background='#FFFFFF'" onMouseOver="this.style.background='red'">
<br>
<input type="button" name="左" style="width:25;height:25" value="-" onClick="showz()" onMouseOut="this.style.background='#FFFFFF'" onMouseOver="this.style.background='red'">
<input type="button" name="中" style="width:25;height:25" value="." onClick="showc()" onMouseOut="this.style.background='#FFFFFF'" onMouseOver="this.style.background='red'">
<input type="button" name="右" style="width:25;height:25" value="-" onClick="showy()" onMouseOut="this.style.background='#FFFFFF'" onMouseOver="this.style.background='red'">
<br>
<input type="button" name="左下" style="width:25;height:25" value="/" onClick="showzx()" onMouseOut="this.style.background='#FFFFFF'" onMouseOver="this.style.background='red'">
<input type="button" name="下" style="width:25;height:25" value="|" onClick="showx()" onMouseOut="this.style.background='#FFFFFF'" onMouseOver="this.style.background='red'">
<input type="button" name="右下" style="width:25;height:25" value="\" onClick="showyx()" onMouseOut="this.style.background='#FFFFFF'" onMouseOver="this.style.background='red'">
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script type="text/javascript">
var names=new Array("左上","上","右上","左","中","右","左下","下","右下");
var values=new Array("↖","↑","↗","←","∙","→","↙","↓","↘");
function DirButtons(parentNode)
{
this.node=document.createElement("table");
var self=this;
var onclick=function(event){self.onclick(event);};
this.buttons=new Array();
for(var i=0;i<3;i++)
{
var tr=this.node.insertRow();
for(var j=0;j<3;j++)
{
var td=tr.insertCell();
var index=i*3+j;
this.buttons[index]=document.createElement("input");
this.buttons[index].setAttribute("type","button");
this.buttons[index].setAttribute("name",index);
this.buttons[index].setAttribute("value",values[index]);
this.buttons[index].style.width="30px";
this.buttons[index].style.height="30px";
if(this.buttons[index].attachEvent)
this.buttons[index].attachEvent("onclick",onclick);
else
this.buttons[index].addEventListener("click",onclick,false);
td.appendChild(this.buttons[index]);
}
}
this.buttons[0].focus();
this.buttons[0].style.backgroundColor="blue";
this.buttons[0].style.color="white";
this.selectedIndex=0;
parentNode.appendChild(this.node);
}
DirButtons.prototype.onclick=function(e)
{
var target;
if(e.srcElement)
target=e.srcElement;
else
target=e.target;
this.buttons[this.selectedIndex].style.backgroundColor="";
this.buttons[this.selectedIndex].style.color="";
this.selectedIndex=parseInt(target.name);
this.buttons[this.selectedIndex].style.backgroundColor="blue";
this.buttons[this.selectedIndex].style.color="white";
if(this.onValueChanged)
this.onValueChanged(names[this.selectedIndex]);
}
DirButtons.prototype.getValue=function()
{
return names[this.selectedIndex];
}
function init()
{
var dirButtons=new DirButtons(document.getElementById("node"));
document.getElementById("dir").appendChild(document.createTextNode(dirButtons.getValue()));
dirButtons.onValueChanged=function(value)
{
document.getElementById("dir").firstChild.nodeValue=value;
}
}
</script>
</head>
<body onload="init()">
<center id="node"><div style="color:red">位置:<span id="dir"></span></div></center>
</body>
</html>