javascript基础知识
javascript:基础知识
1 创建脚本块
1: <script language=”javascript”>
2: javascript code goes here
3: </script>
2 隐藏脚本代码
1: <script language=”javascript”>
2: <!--
3: document.write(“Hello”);
4: // -->
5: </script>
在不支持javascript的浏览器中将不执行相关代码
3 浏览器不支持的时候显示
1: <noscript>
2: Hello to the non-javascript browser.
3: </noscript>
4 链接外部脚本文件
1: <script language=”javascript” src="/”filename.js"”></script>
5 注释脚本
1: // This is a comment
2: document.write(“Hello”); // This is a comment
3: /*
4: All of this
5: is a comment
6: */
6 输出到浏览器
1: document.write(“<strong>Hello</strong>”);
7 定义变量
1: var myVariable = “some value”;
8 字符串相加
1: var myString = “String1” + “String2”;
9 字符串搜索
1: <script language=”javascript”>
2: <!--
3: var myVariable = “Hello there”;
4: var therePlace = myVariable.search(“there”);
5: document.write(therePlace);
6: // -->
7: </script>
10 字符串替换
1: thisVar.replace(“Monday”,”Friday”);
11 格式化字串
1: <script language=”javascript”>
2: <!--
3: var myVariable = “Hello there”;
4: document.write(myVariable.big() + “<br>”);
5: document.write(myVariable.blink() + “<br>”);
6: document.write(myVariable.bold() + “<br>”);
7: document.write(myVariable.fixed() + “<br>”);
8: document.write(myVariable.fontcolor(“red”) + “<br>”);
9: document.write(myVariable.fontsize(“18pt”) + “<br>”);
10: document.write(myVariable.italics() + “<br>”);
11: document.write(myVariable.small() + “<br>”);
12: do
相关文档:
以创建按钮为例
<html>
<head>
<script>
function add1()
{
var obtn=document.createElement("input");
obtn.setAttribute("type","button");
obtn.setAttribute("value","test1");
document.body.appendChild(obtn);//注意如果有f ......
说明:这篇文章节选自John Resig
的《Secrets of the JavaScript Ninja》一书,本人翻译只是供大家学习,翻译不足之处,请斧正。
这篇文章主要从下面几个方面解读计时器:
计时器概述;
计时器速度深度探析;
用计时器处理大量任务;
利用计时器管理动画;
较好的计时器测试
计时器是一个我们了解很少且经常被 ......
直接使用未定义的Javascript变量时,页面会报错并无法执行,比如
if (varName=="")
{
}
需要先判断变量是否定义,使用typeof函数可以判断,如下使用:
if (typeof(ipaddr)=='undefined')
{
window.alert('ipaddr未定义');
} ......
转自http://topic.csdn.net/u/20091014/12/44b0ac69-5228-429b-854a-a91e3736f1d4.html?64368
每一项都是JS中的小技巧,但十分的实用!
1.document.write(”"); 输出语句
2.JS中的注释为//
3.传统的HTML文档顺序是:document->html->(head,body)
4.一个浏览器窗口中的DOM顺序是:window->(navig ......
POST代替FORM
<SCRIPT language="VBScript">
Function URLEncoding(vstrIn)
strReturn = ""
For i = 1 To Len(vstrIn)
ThisChr = Mid(vStrIn,i,1)
If Abs(Asc(ThisChr)) ......