javascript onmouseover 内部母版页问题
您好,我目前正在开发一个 asp.net 项目,我需要制作一个按钮,当用户从左到右或从右到左移动光标时,会填充隐藏的文本字段,然后调用服务器端的 dopostback读取该隐藏字段的值。
我的问题是,当我创建事件侦听器时,它不会调用,因此 pageX 不起作用。我目前正在 Google chrome 浏览器上进行测试,我已经在 IE 中测试了 clientX 部分并且运行良好。
这是编码的 .aspx 一侧
<asp:Button ID="Button2" runat="server" Text="<<<------ ------>>>"
Width="50%" Height="60px" onclick="Button2_Click"
onmouseover="getMouseXY()" onmouseout="getMouseOut()"/>
<script type="text/javascript">
var IE = document.all?true:false;
var dayD = 0;
var inCordX = 0;
var outCordX = 0;
if (!IE)
document.captureEvents(Event.MOUSEMOVE)
function getMouseOut(e){
if (IE) {outCordX = event.clientX + document.body.scrollLeft;}
else {outCordX = e.pageX;}
if(inCordX>outCordX){dayD=1;}else{dayD=-1;}
document.getElementById("outputResult").value = dayD;
__doPostBack("","");
}
function getMouseXY(e) {
if (IE) {inCordX = event.clientX + document.body.scrollLeft;}
else {inCordX = e.pageX;}
alert(inCordX);
return true;
}
</script>
这是编码 aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if ((Request.Form["outputResult"] == "-1")
||(Request.Form["outputResult"] == "-1"))
{
Button2_Click(this, new EventArgs());
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Button2.Text = Request.Form["outputResult"] + "";
}
Hi I'm currently working on a asp.net project and I need to make a button which when the user moves the cursor from left to right or right to left a hidden text field is filled and then a dopostback is called for the serverside to read the value of that hidden field.
My problem is that when I create the event listener it doesn't call, thus the pageX does not work. I'm currently testing on Google chrome browser, I've tested the clientX part in the IE and works well.
This is the .aspx side of the cording
<asp:Button ID="Button2" runat="server" Text="<<<------ ------>>>"
Width="50%" Height="60px" onclick="Button2_Click"
onmouseover="getMouseXY()" onmouseout="getMouseOut()"/>
<script type="text/javascript">
var IE = document.all?true:false;
var dayD = 0;
var inCordX = 0;
var outCordX = 0;
if (!IE)
document.captureEvents(Event.MOUSEMOVE)
function getMouseOut(e){
if (IE) {outCordX = event.clientX + document.body.scrollLeft;}
else {outCordX = e.pageX;}
if(inCordX>outCordX){dayD=1;}else{dayD=-1;}
document.getElementById("outputResult").value = dayD;
__doPostBack("","");
}
function getMouseXY(e) {
if (IE) {inCordX = event.clientX + document.body.scrollLeft;}
else {inCordX = e.pageX;}
alert(inCordX);
return true;
}
</script>
This is the coding aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if ((Request.Form["outputResult"] == "-1")
||(Request.Form["outputResult"] == "-1"))
{
Button2_Click(this, new EventArgs());
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Button2.Text = Request.Form["outputResult"] + "";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不太确定,但尝试
代替
Not so sure, but try
instead of