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: document.write(myVariable.strike() + "<br>");
13: document.write(myVariable.sub() + "<br>");
14: document.write(myVariable.sup() + "<br>");
15: document.write(myVariable.toLowerCase() + "<br>");
16: document.write(myVariable.toUpperCase() + "<br>");
17:
相关文档:
javascript中eval详细理解
2009-02-27 14:58
2008-04-12 00:29
首先来个最简单的理解
eval可以将字符串生成语句执行,和SQL的exec()类似。
eval的使用场合是什么呢?有时候我们预先不知道要执行什么语句,只有当条件和参数给时才知道执行什么语句,这时候eval就派上用场了。举个例子:
& ......
网上正则表达式的教程够多了,但由于javascript的历史比较悠久,也比较古老,因此有许多特性是不支持的。我们先从最简单地说起,文章所演示的正则基本都是perl方式。
元字符
( [ { \ ^ $ | ) ? * + .
预定义的特殊字符
.table1 {
border:1px solid #666;border-collapse:collapse;width:7 ......
学用JS(javascript)语句大全。对初学者很有帮助 。现在整理出来,希望能帮助大家。
1.document.write(""); 输出语句
2.JS中的注释为//
3.传统的HTML文档顺序是:document->html->(head,body)
4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document)
5.得到表单中元素的名称和 ......
Javascript中的常见问题
1. 集合类对象问题
现有代码中许多集合类对象取用时使用 (),IE 能接受,Firefox 不能。
解决方法:改用 [] 作为下标运算。如:document.forms("formName") 改为
Js代码
document.forms[
"formName"
];
//又如:
document.getEle ......