62,074
社区成员
发帖
与我相关
我的任务
分享
<script>
var array = new Array("北京","天津","上海","重庆","河北","河南","湖北","湖南","江苏","山西","陕西","甘肃","四川");
var div;
function ShowDiv()
{
if(div==null)
{
div = document.createElement("div");
div.id = "div1";
div.style.left = document.body.scrollLeft+ event.clientX-event.offsetX;
div.style.top = document.body.scrollTop+event.clientY-event.offsetY-18;
div.position = "absolute";
div.style.width="200px";
div.style.Height="100px";
div.style.background="#cccccc";
div.style.borderLeft="1px solid black";
div.style.borderTop="1px solid black";
div.style.borderBottom="1px solid black";
div.style.borderRight="1px solid black";
div.style.fontSize="11px";
for(i =0 ; i < array.length;i++)
{
div.innerHTML += "<a style='cursor:hand' onclick='getvalue(this.innerHTML)'>"+array[i]+"</a>";
}
document.body.appendChild(div);
}
else
{
document.getElementById("div1").style.display='';
}
}
function getvalue(val)
{
document.getElementById("Text1").value=val;
document.getElementById("div1").style.display='none';
}
function HiddenDiv()
{
document.getElementById("div1").style.display='none';
}
</script>
</head>
<body>
<form id="form1" runat="server">
<p />
<input id="Text1" type="text" value="选择省" onblur="if (this.value=='') this.value=this.defaultValue;HiddenDiv()" onfocus="if (this.value==this.defaultValue) this.value='';ShowDiv();event.cancelBubble=true;return false" />
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>event.cancelBubble</title>
<style>
<!--
* {font:menu}
-->
</style>
</head>
<body>
<span onclick=alert("你好")>点我 <span>再点我</span></span><br><br>
<span onclick=alert("你好")>点我 <span onclick=event.cancelBubble=true;>再点我</span></span>
</body>
</html>
<html>
<head><script>
var array = new Array("北京","天津","上海","重庆","河北","河南","湖北","湖南","江苏","山西","陕西","甘肃","四川");
var div;
function ShowDiv(txt)
{
if(div==null)
{
div = document.createElement("div");
div.id = "div1";
div.style.position = "absolute";//============少了style
div.style.width="200px";
div.style.Height="100px";
div.style.background="#cccccc";
div.style.borderLeft="1px solid black";
div.style.borderTop="1px solid black";
div.style.borderBottom="1px solid black";
div.style.borderRight="1px solid black";
div.style.fontSize="11px";
//===================
var pos=GetPos(txt);
div.style.left =pos.x;
div.style.top = pos.y;
for(i =0 ; i < array.length;i++)
{
div.innerHTML += "<a style='cursor:hand' onclick='getvalue(this.innerHTML)'>"+array[i]+"</a>";
}
document.body.appendChild(div);
}
else
{
document.getElementById("div1").style.display='';
}
}
function GetPos(txt)
{
var pos=new Object();
pos.x=txt.offsetLeft;
pos.y=txt.offsetTop+txt.offsetHeight;
while(txt=txt.offsetParent)
{
pos.x+=txt.offsetLeft;
pos.y+=txt.offsetTop;
}
return pos;
}
function getvalue(val)
{
document.getElementById("Text1").value=val;
HiddenDiv()
}
function HiddenDiv()
{
document.getElementById("div1").style.display='none';
}
document.onclick=function(e)
{
e=e||event;
var tag=e.srcElement||e.target;
if(tag.id!="Text1")
HiddenDiv();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<p />
<input id="Text1" type="text" value="选择省" onclick="ShowDiv(this);" />
</form>
</body>
</html>
在
function getvalue()
{
alert(this.innerHTML);
}
怎么不行 直接在a标签里这样可以 this不是指调用的对象吗
<input id="Text1" type="text" value="选择省" onFocus="if (this.value==this.defaultValue) this.value='';ShowDiv();event.cancelBubble=true;return false" />