• JavaScript笔记(第一章,第二章)


    JavaScript笔记(第一章,第二章)

    第一章:

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

    <script type="text/javascript" src="lesson2.js"></script>

    Lesson2.js

    document.write("<div style='font-size:36px; color:red'>");

    document.write("欢迎使用JavaScript !");

    document.write("</div>");

    第二章:

    var score ; //定义变量score代表分数

    score = prompt("请输入成绩","fry"); //使用window对象的prompt()方法,弹出一个输入框

    后一个参数是默认值

    document.write("<span style=font-size:36px;font-family:Webdings;>"

    +character+"</span>");

    <span> 标签被用来组合文档中的行内元素。其实相当于Java中的{},不同的是span能给组合起来的东西设置格式。

    document.write("<p>请输入几个字母看看效果:</p>");

    <p> 标签定义段落。

    p 元素会自动在其前后创建一些空白。浏览器会自动添加这些空间,您也可以在样式表中规定。

    do

    {

    }while(character!="n"&&character!="N")

    等于字符怎么写,等于号和双引号,还有do-while后面没有分号

    document.write(row+"*"+col+"="+row*col+"&nbsp;&nbsp;");

    空格 &nbsp;

    有事件处理,有函数,有表格,还有控件,document对象

    <html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

    <title>计算器</title>

    <script type="text/javascript">

    <!--

    function calc(sign)

    {

    var firstValue=document.calcform.first.value;

    var secondValue=document.calcform.second.value;

    var resultValue ; //结果

    //在这里,我们默认用户输入都是数字,不作验证, 直接转换成数字

    var num1 = parseFloat(firstValue);

    var num2  = parseFloat(secondValue);

          if(sign=="+")

          {

                resultValue =num1 + num2 ;

          }

          if(sign=="-")

          {

               resultValue =num1 - num2 ;

          }

          if(sign=="*")

          {

               resultValue =num1  *  num2 ;

          }

          if(sign=="/")

          {

               resultValue =num1 / num2 ; /*实际上在作除法运算,要判断除数是不是为零,如果是,提示,除数不能为零,否则,显示*/

          }

         document.calcform.result.value = resultValue ;

    }

    // -->

    </script>

    </head>

    <body>

    <form name="calcform">

    <table width="388" height="80" border="0">

      <tr><td width="127">第一个数</td>

        <td width="131">第二个数</td>

        <td width="116">结果</td></tr>

      <tr><td><input type="text" name="first" size="12" /></td>

        <td><input type="text" name="second" size="12" /></td>

        <td><input type="text" name="result" size="14" /></td></tr>

      <tr><td colspan="3">运算类型:

               <input type="button" value="+" onclick="calc('+')" />

               <input type="button" value="-" onclick="calc('-')"  />

               <input type="button" value="*" onclick="calc('*')"  />

               <input type="button" value="/" onclick="calc('/')"  />

          </td></tr>

    </table></form>

    </body></html>

    <form> 标签用于为用户输入创建 HTML 表单。

    表单能够包含 input 元素,比如文本字段、复选框、单选框、提交按钮等等。

    表单还可以包含 menustextareafieldsetlegend 和 label 元素

    表单用于向服务器传输数据。

    <html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

    <title>内置函数实现求和</title>

    <script type="text/javascript">

    <!--

    function sum()

    {

          var resultValue , firstValue ,secondValue; //声明3个变量,不给初值

        firstValue  = document.myform.first.value ;

         secondValue = document.myform.second.value;

          if(isNaN(firstValue))

          {

             alert(firstValue+"不是一个数字!");

           return; /*注意,这里使用了return语句,表示程序走到这里就返//回了,下面的语句不被执行了。如果,思考下,去掉return,会怎样呢?*/

          }

          if(isNaN(secondValue))

          {

               alert(secondValue+"不是一个数字!");

               return;

          }

     var num1=parseFloat(firstValue);

           var num2=parseFloat(secondValue);

         resultValue = num1 + num2 ;

           document.myform.result.value = resultValue;

    }

     //-->

    </script>

    </head>

    <body style="font-size:12px;">

    <form name="myform">

    加数:<input type="text" name="first" size=6>

    被加数:<input type="text" name="second" size=6>

    <input type="button" onclick="sum()" value="求和">&nbsp;

    <input type="text" name="result" size=6>

    </form>

    </body>

    </html>

    if(counter == 10){

         break;

    }

    等于号

  • 相关阅读:
    list中的对象或者map中的版本号排序 version排序
    spring boot jpa 复杂查询 动态查询 连接and和or 模糊查询 分页查询
    java 8 list的stream操作 list中的对象中的某一个成员取出转为该成员的list,以及对象过滤,筛选某个属性后的成员
    map或者对象转换
    Feign代理必须加value否则启动失败
    Eclipse中.setting目录下文件介绍
    远程仓库版本回退方法
    SpringMVC异常处理机制
    android studio启动和项目编译问题
    CentOS6.5安装php7+nginx+mysql实现安装WordPress
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/7677702.html
Copyright © 2020-2023  润新知