由于一直改人家做好的,感觉总是不那么尽善尽美,所以自己先学下基础,先弄这些其他随着学习慢慢来!

1.学习简单的输出!

<script type="text/javascript">

document.write("Hello World!");

</script>



2.防止不支持js的浏览器显示出来!

<script type="text/javascript">



document.write("Hello World!");

//

</script>



3.页面弹出提示!

<script type="text/javascript">alert("错误提示!")</script>



4.外部调用js文件.

<script src="/js/test.js">



5.动作来触发弹出提示!

<script type="text/javascript">

function message()

{

alert("错误提示!")

}

</script>

</head>



<body onload="message()">



6.输出html内容

<script type="text/javascript">

{

document.write("<h1>This is a header</h1>");

document.write("<p>This is a paragraph</p>");

document.write("<p>This is another paragraph</p>");

}

</script>



6.js常见方式注释

<script type="text/javascript">

// 这行代码输出标题:

document.write("<h1>This is a header</h1>");

// 这行代码输出段落:

document.write("<p>This is a paragraph</p>");//这里以后注释掉

/*document.write("<p>This is another paragraph</p>");这里也注释没了*/

</script>



7.javascript变量一些演示( 加 -减 *乘 /除 累加 --累减):



<script type="text/javascript">

var x=1;

document.write(x);

</script>

结果: 1



<script type="text/javascript">

var x=1;

var y=2;

var z=x y

document.write(z);

</script>

结果: 3



<script type="text/javascript">

var x=1;

var y=2;

var z="x" y;

document.write(z);

</script>

结果: x2



<script type="text/javascript">

var x=1;

var y=2;

var z="x" "y";

document.write(z);

</script>

结果: xy



9.根据判断条件来输出结果!

<script type="text/javascript">

var age="1";

if (age<18)

document.write("Too young");

else

document.write("Too old");

</script>





....

其他陆续学习添加~~~
<div class="tags" style="display: block">Tags: 坏狼 , javascript , 语法 , 学习[/code]
[/code]