JavaScript方法和技巧大全
JavaScript方法和技巧大全 基础知识
1 创建脚本块 <script language=”JavaScript”> JavaScript code goes here </script>
2 隐藏脚本代码 <script language=”JavaScript”><!-- document.write(“Hello”); --> </script>
在不支持JavaScript的浏览器中将不执行相关代码
3 浏览器不支持的时候显示 <noscript> Hello to the non-JavaScript browser.</noscript>
4 链接外部脚本文件<script language=”JavaScript” src="/”filename.js"”></script>
5 注释脚本 // This is a comment
document.write(“Hello”); // This is a comment
/* All of this is a comment */
6 输出到浏览器 document.write(“<strong>Hello</strong>”);
7 定义变量 var myVariable = “some value”;
8 字符串相加 var myString = “String1” + “String2”;
9 字符串搜索 <script language=”JavaScript”><!-- var myVariable = “Hello there”;
var therePlace = myVariable.search(“there”); document.write(therePlace);// --> </script>
10 字符串替换 thisVar.replace(“Monday”,”Friday”);
11 格式化字串 <script language=”JavaScript”><!—
var myVariable = “Hello there”; document.write(myVariable.big() + “<br>”);
document.write(myVariable.blink() + “<br>”); document.write(myVariable.bold() + “<br>”);
document.write(myVariable.fixed() + “<br>”);document.write(myVariable.fontcolor(“red”) + “<br>”);
document.write(myVariable.fontsize(“18pt”) + “<br>”);document.write(myVariable.italics() + “<br>”);
document.write(myVariable.small() + “<br>”);document.write(myVariable.strike() + “<br>”);
相关文档:
上了一天的课,很累,不过真的很充实.比自己学的效率要高很多,对技术的理解也提高了不少.对总结有充满了信心,感觉自己两个半月后一定能找到一个五千块以上的工作.哈哈!今天讲的是JavaScript的应用.主要是在项目和工作中经常使用到的功能实现.老师对JavaScript的总结和运用很全面和实用.先简单介绍几句教我JavaScript的老师,佟 ......
<html>
<head></head>
<script>
function ShowMenu(bMenu) {
document.all.idFinder.style.display = (bMenu) ? "none" : "block"
document.all.idMenu.style.display = (bMenu) ? "block" : "none"
idML.className = (bMenu) ? "cOn" : "cOff"
idRL.className = (bMenu) ? "cOff" : "cOn" ......
function GetUrlParms(){
var args=new Object();
var query=location.search.substring(1);//获取查询串
var pairs=query.split("&");//在逗号处断开
for(var i=0;i<pairs.length;i++){
var pos=pairs[i].indexOf('=');//查找name=value
if(pos==-1) c ......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>随机 ......