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运行代码框代码
<script language="JavaScript" type="text/JavaScript">
//运行文本域代码
function runEx(cod1) {
cod=document.all(cod1)
var code=cod.value;
if (code!=""){
var newwin=window.open(’’,’’,’’); //打开一个窗口并赋给变量newwin。 ......
尽管那需要用长串的、沉闷的不同分支代码来应付不同浏览器的日子已经过去,偶尔还是有必要做一些简单的区分和目标检测来确保某块代码能在用户的机器上正常运行。在这篇文章中,作者介绍了7个在IE和firefox中不同的JavaScript句法。
1. CSS "float" 值
访问一个给定CSS 值的最基本句法 ......
JavaScript语言和Java语言是相关的,但它们之间的联系并不像想象中的那样紧密。
二者的区别体现在:
首先,它们是两个公司开发的不同的两个产品,Java是SUN公司推出的新一代面向对象的程序设计语言,特别适合于Internet应用程序开发;而JavaScrip ......
<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" ......
String
字符串对象。声明一个字符串对象最简单、快捷、有效、常用的方法就是直接赋值。
属性
length
用法:<字符串对象>.length;返回该字符串的长度。
方法
......