javascript学习笔记

<html>

<body>



<script type="text/javascript">

/*
下面的代码将输出
一个标题和两个段落
*/

// 这行代码输出标题:

document.write("<h1>这是标题</h1>");
// 这行代码输出段落: document.write("<p>这是段落。</p>"); document.write("<p>这是另一个段落。</p>");//生成文本 </script> </body> </html>

  生成文本  注释

<html>

<body>



<script type="text/javascript">

	{

	document.write("<h1>这是标题</h1>");

	document.write("<p>这是段落。</p>");

	document.write("<p>这是另一个段落。</p>");

	}

</script>



</body>

</html>

  代码块

 

<html>

<body>



<script type="text/javascript">

var firstname;

firstname="George";

document.write(firstname);

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

firstname="John";

document.write(firstname);

</script>



<p>上面的脚本声明了一个变量,为其赋值,显示该值,改变该值,然后再显示该值。</p>



</body>

</html>

  

<html>

<body>



<script type="text/javascript">

var d=new Date()

document.write(d)

var time = d.getHours()



if (time < 5) 

{

document.write("<b>晚安</b>")

}

else if(time < 10)

{

document.write("<b>早安</b>")

}

else{

document.write("<b>好好工作</b>")

}

</script>



<p>本例演示 If ...elseif...else...语句。</p>



<p>如果浏览器时间小于 10大于5,那么会向您问“早安”。</p>



</body>

</html>

  

<html>

<body>



<script type="text/javascript">

var r=Math.random()

if (r>0.5) 

{

document.write("<a href='http://www.w3school.com.cn'>学习 Web 开发!</a>")

}

else

{

document.write("<a href='http://www.microsoft.com'>访问微软!</a>")

}

</script>



</body>

</html>

  随机数加拼接页面超链接

 

<html>

<head>

<script type="text/javascript">

function disp_alert()

{

alert("再次向您问好!在这里,我们向您演示" + '\n'+ "如何向警告框添加折行。")

}

</script>

</head>



<body>



<input type="button" onclick="disp_alert()" value="显示警告框" />



</body>

</html>

  弹出框加折行显示

 

<html>

<head>

<script type="text/javascript">

function show_confirm()

{

var r=confirm("Press a button!");

if (r==true)

  {

  alert("You pressed OK!");

  }

else

  {

  alert("You pressed Cancel!");

  }

}

</script>

</head>

<body>



<input type="button" onclick="show_confirm()" value="Show a confirm box" />



</body>

</html>

  确认框

你可能感兴趣的:(JavaScript)