网页效果获取鼠标点击的位置
2011-08-05 10:51
399 查看
1.首先来看一个简单的获取鼠标位置:
<a href="javascript:void(0);" onclick="x(this)" alt='aa' >aaa</a>
<br>
<input type="text" onclick="x(this)" value="cccc1">
<br>
<input type="text" onclick="x(this)" value="cccc2">
<br>
<input type="text" onclick="x(this)" value="cccc3">
<br>
<input type="text" onclick="x(this)" value="cccc4">
<div id="div1"></div>
<script>
function x(o)
{
document.all.div1.style.visibility="visible";
document.all.div1.innerText=o.value;
document.all.div1.style.top=event.clientY;
document.all.div1.style.left=event.clientX;
alert(event.clientX+ " "+event.clientY);
var a = window.event.x;
var b = window.event.y;
alert(a+" "+ b);
}
</script>
2, 获取鼠标位置后,我们就可以控制window.open的位置。
<script>
function ccc()
{
k=window.showModalDialog("a.html",null,"dialogwidth:145px;dialogheight:155px;dialogtop:"+ event.screenY+";dialogleft:" + event.screenX);
}
</script>
<input type="text" value="" onclick="ccc()" >
3,做了一个弹出层,点击层外面也可以关闭层。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Popup-Window</TITLE>
<style>
#alert {font-size:12px;border:1px solid #369;width:200px;height:50px;background:#e2ecf5;z-index:1000;position:absolute;}
</style>
<script>
function hid()
{
var myAlert = document.getElementById("alert");
myAlert.style.display = "none";
}
function onsub(name)
{
// mClose.onclick();
hid();
document.getElementById("new_one").value=name.innerText;
}
function new_hid()
{
hid();
}
</script>
</HEAD>
<BODY>
<Br><Br><Br>
<span id="content"><input type="text" value="" class="tx4" id="new_one"></span>
<div id="alert" style="display:none;">
<p><a href="javascript:void(0);" onclick="onsub(this);">test1</a></p>
<p><a href="javascript:void(0);" onclick="onsub(this);">test2</a></p>
<p><a href="javascript:void(0);" onclick="onsub(this);">test3</a></p>
<p><a href="javascript:void(0);" onclick="onsub(this);">test4</a></p>
<p><center><span id="close" style="cursor:hand;">close</span></center></p>
</div>
<div style="width:100%;height:100%;" onclick="new_hid();"></div>
<script type="text/javascript">
var myAlert = document.getElementById("alert");
var reg = document.getElementById("new_one");
var mClose = document.getElementById("close");
reg.onclick = function()
{
myAlert.style.display = "block";
//myAlert.style.position = "absolute";
//myAlert.style.width="200px";
//myAlert.style.height="200px";
// var a = window.event.x;
// var b = window.event.y;
// alert(a+ " "+b);
myAlert.style.top=event.clientY;
myAlert.style.left=event.clientX;
}
mClose.onclick = function()
{
myAlert.style.display = "none";
}
</script>
</BODY>
</HTML>
<a href="javascript:void(0);" onclick="x(this)" alt='aa' >aaa</a>
<br>
<input type="text" onclick="x(this)" value="cccc1">
<br>
<input type="text" onclick="x(this)" value="cccc2">
<br>
<input type="text" onclick="x(this)" value="cccc3">
<br>
<input type="text" onclick="x(this)" value="cccc4">
<div id="div1"></div>
<script>
function x(o)
{
document.all.div1.style.visibility="visible";
document.all.div1.innerText=o.value;
document.all.div1.style.top=event.clientY;
document.all.div1.style.left=event.clientX;
alert(event.clientX+ " "+event.clientY);
var a = window.event.x;
var b = window.event.y;
alert(a+" "+ b);
}
</script>
2, 获取鼠标位置后,我们就可以控制window.open的位置。
<script>
function ccc()
{
k=window.showModalDialog("a.html",null,"dialogwidth:145px;dialogheight:155px;dialogtop:"+ event.screenY+";dialogleft:" + event.screenX);
}
</script>
<input type="text" value="" onclick="ccc()" >
3,做了一个弹出层,点击层外面也可以关闭层。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Popup-Window</TITLE>
<style>
#alert {font-size:12px;border:1px solid #369;width:200px;height:50px;background:#e2ecf5;z-index:1000;position:absolute;}
</style>
<script>
function hid()
{
var myAlert = document.getElementById("alert");
myAlert.style.display = "none";
}
function onsub(name)
{
// mClose.onclick();
hid();
document.getElementById("new_one").value=name.innerText;
}
function new_hid()
{
hid();
}
</script>
</HEAD>
<BODY>
<Br><Br><Br>
<span id="content"><input type="text" value="" class="tx4" id="new_one"></span>
<div id="alert" style="display:none;">
<p><a href="javascript:void(0);" onclick="onsub(this);">test1</a></p>
<p><a href="javascript:void(0);" onclick="onsub(this);">test2</a></p>
<p><a href="javascript:void(0);" onclick="onsub(this);">test3</a></p>
<p><a href="javascript:void(0);" onclick="onsub(this);">test4</a></p>
<p><center><span id="close" style="cursor:hand;">close</span></center></p>
</div>
<div style="width:100%;height:100%;" onclick="new_hid();"></div>
<script type="text/javascript">
var myAlert = document.getElementById("alert");
var reg = document.getElementById("new_one");
var mClose = document.getElementById("close");
reg.onclick = function()
{
myAlert.style.display = "block";
//myAlert.style.position = "absolute";
//myAlert.style.width="200px";
//myAlert.style.height="200px";
// var a = window.event.x;
// var b = window.event.y;
// alert(a+ " "+b);
myAlert.style.top=event.clientY;
myAlert.style.left=event.clientX;
}
mClose.onclick = function()
{
myAlert.style.display = "none";
}
</script>
</BODY>
</HTML>
相关文章推荐
- 在WebBrowser控件中获取鼠标在网页(不是浏览器窗口)上点击的位置,
- 在WebBrowser控件中获取鼠标在网页上点击的位置
- 在WebBrowser控件中获取鼠标在网页上点击的位置
- ASP.NET gridview中点击任意行的任意位置选中某行交替效果 变换鼠标手势,获取选定行的指写数据
- 基于JavaScript实现 获取鼠标点击位置坐标的方法
- js获取鼠标点击的位置实现思路及代码
- VS2010/MFC 获取ListControl鼠标点击位置
- js获取鼠标点击位置
- js获取鼠标点击事件的相对位置
- 获取鼠标点击的位置
- JavaScript 获取鼠标点击位置坐标
- JS 获取鼠标点击位置
- MFC 获取picture控件的鼠标点击坐标位置的方法
- ASP.NET2005 gridview中点击某行的任意位置选中某行 交替效果 变换鼠标手势
- [JavaScript]获取鼠标点击区域的相对、绝对位置坐标
- javascript获取鼠标点击位置的兼容写法
- JavaScript 获取鼠标点击位置坐标
- JavaScript 获取鼠标点击位置坐标
- JavaScript 获取鼠标点击位置坐标
- js获取页面元素和鼠标的点击位置