为什么把div的class换成id,使用getElementsById可以实现,用getElementsByClassName不能实现
<scripttype="text/javascript">window.onload=function(){vartextbox=document.getElement...
<script type="text/javascript">
window.onload = function()
{
var textbox = document.getElementById("textbox");
var val = "";
document.getElementsByClassName("box").onmousedown = function(e)
{
e = window.event || e;
val =
"e.screenX:" + e.screenX +
"\ne.screenY:" + e.screenY ;
}
</script>
</head>
<body>
<div class="box"></div>
<textarea id="textbox" style="display:block; margin:50px auto 0; width:400px; height:200px;"></textarea>
</body> 展开
window.onload = function()
{
var textbox = document.getElementById("textbox");
var val = "";
document.getElementsByClassName("box").onmousedown = function(e)
{
e = window.event || e;
val =
"e.screenX:" + e.screenX +
"\ne.screenY:" + e.screenY ;
}
</script>
</head>
<body>
<div class="box"></div>
<textarea id="textbox" style="display:block; margin:50px auto 0; width:400px; height:200px;"></textarea>
</body> 展开
2个回答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询