求问!代码没有实现应有的效果是什么原因?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>动画菜单</title>
  <style>
   *{margin:0;padding:0;}
     .head{font-size:12px;padding:6px 0 0 10px;}
     #login_box{width:300px;height:150px;background:#eee;
     border:1px solid #ccc;position:absolute;left:50%;top:50%;margin-left:-150px;margin-top:-75px;display:none;}
     #login_box p{height:20px;border-bottom:1px solid #ccc;font-size:12px;padding:6px 0 0 5px;font-weight:bold;}
     #close{width:14px;height:14px;position:absolute;right:4px;top:6px;}
  </style>
  <script type="text/javascript" src="http://code.jquery.com/jquery-3.2.0.min.js"></script>
  <script>
    
     $("#login").click(function(){
      $("#login_box").css("display","block");
    });
    
    $("#close").click(function(){
      $("#login_box").css("display","none");
    });
  </script>
</head>
<body>
  <div class="head">亲,您好!<input type="button" value="登 录" id="login"></div>
  <div id="login_box">
    <p>用户登录</p><span id="close">X</span>
  </div>
</body>
</html>

/*点击按钮后,<div id="login_box">的display没有改变,哪出了问题?*/

阿莫3912736
浏览 1120回答 1
1回答

阿莫3912736

发现了是页面加载的问题。。。套一层$(function(){})解决问题。。
打开App,查看更多内容
随时随地看视频慕课网APP