JScript&JQuery学习

来源:互联网 发布:mac常用的软件 编辑:程序博客网 时间:2024/05/22 09:07
网易云课堂
JScript 脚本语言 解释语言
1,语法
<script type="text/javascript">
</script>
2,通过标签的id获取值
var o=document.getElementById('user');
3,JS的外部引用写法
<script src="fun.js" type="text/javascript"></script>

4,JQuery jQuery 是一个 JavaScript 库.

javascript.html<html><head charset="utf-8">    <title> JScript学习 </title>      <script src="fun.js" type="text/javascript"></script>      <script type="text/javascript">      function aa(){          //alert("hello world");          //通过标签的id获取值          var o=document.getElementById('user');          if(o.value=="")          {            alert("aa用户名不能为空");          }      }     </script></head><body> 用户名:<input type="text" id="user"/><br/> <input type="button" value="提交" onclick="aa()"></input> <div style="width:155px; height:155px; border:1px solid blue; background : red" onclick="bb()"> 这是div </div></body></html>

fun.js
 function bb(){
          //alert("hello world");
          //通过标签的id获取值
          var o=document.getElementById('user');
          if(o.value=="")
          {
            alert("bb用户名不能为空");
          }
      }
       function cc(){
          //alert("hello world");
          //通过标签的id获取值
          var o=document.getElementById('user');
          if(o.value=="")
          {
            alert("cc用户名不能为空");
          }
      }
jquery.html
<html>
<head charset="utf-8">
    <title> JQuery学习 </title>
     <script src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
     <script type="text/javascript">
      $(document).ready(function(){
          $("#divtest").click(function()
          {alert("jquery alert");});
          $("#divtest").css({"color":"black","background":"yellow"})
      });
     </script>

</head>
<body>
 用户名:<input type="text" id="user"/><br/>
 <input type="button" value="提交" onclick="cc()"></input>
 <div id="divtest" style="width:155px; height:155px; border:1px solid blue; background : red">
 这是div
 </div>
</body>
</html>

                                             
0 0
原创粉丝点击