获取鼠标点击的坐标处理

1.编写js :

 function whichElement(e)
    {
        x=e.x
        y=e.y
        m = document.getElementById('GV_Car');
        var h = 0;
        while(m.offsetParent)
        {
         h += m.offsetTop;
         m = m.offsetParent;
        }
        m = document.getElementById('div_info');
        var t = 0;
        while(m.offsetParent)
        {
         t += m.offsetTop;
         m = m.offsetParent;
        }
        var yy = document.getElementById('txt_YY').value;
        if (y > 74)
        {
            if (h <= y && y < t)
            {
                document.getElementById('txt_YY').value = "1";
            }
            else
            {
                document.getElementById('txt_YY').value = "0";              
            }
        }     
    }

2. 调用js:

<body onmousedown="whichElement(event)">

你可能感兴趣的:(获取)