javascript onmouseover 内部母版页问题

发布于 2024-11-14 19:14:10 字数 1821 浏览 1 评论 0原文

您好,我目前正在开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

送君千里 2024-11-21 19:14:10

不太确定,但尝试

  onmouseover="getMouseXY" onmouseout="getMouseOut"/> 

代替

  onmouseover="getMouseXY()" onmouseout="getMouseOut()"/> 

Not so sure, but try

  onmouseover="getMouseXY" onmouseout="getMouseOut"/> 

instead of

  onmouseover="getMouseXY()" onmouseout="getMouseOut()"/> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文