Javascript基本语法,a-href、img-src、button按钮使用时的跳转问题

1.在<script>...</script>中进行显示;

2.对于返回值的问题,需要使用到alart()函数,其也存在return,

        <script>  

                        function  demo(a,b){

                            if(a>b)

                                  return alart("a比较大!");

                            else

                                  return("b比较大!");

                        }

                               var  vl=demo(100,20);

                               document.getElementById("myid").innerHTML=vl;

          或是:document.getElementById("myid").innnerHTML=demo(10,20);

        </script>

3.script 中在点击按钮事件button时,若要在同一界面显示不覆盖的前提话,需要使用如下:
        <body>

                <p id="myid">hello</p>

                <button onclick="demo()">按钮</button>

                <script>  

                        function  demo(){

                            var nv=document.getElementById("myid").innerHTML="wps";

                        }

                </script>

          </body>

4.script中对img,a标签使用,
         <a id="aid" href= http://www.baidu.com>hello!</a>
         <button onclick="demo()">按钮</button>

                <script>  

                        function demo(){

                            document.getElementById("myid").href="http://www.jikexueyuan.cn";

                        }

                </script>

        注:若为img时,将“href”改为“src”即可;



你可能感兴趣的:(JavaScript,html,href)