JScript 有许多保留字,它们在 JScript 语言语法中有特定的意义。因此,这些字不宜作为脚本中的函数、变量或常数的名称。总共有三类保留字。受保护的保留字
break case catch class const
continue debugger default delete do
else export extends false finally
for function if import in
instanceof new null protected return
super switch this throw true
try typeOf var while with 受保护的保留字不能用作标识符。将受保护的保留字用作标识符会在加载脚本时引起编译错误。注意 尽管“export”是一个受保护的保留字,但它没有实现方法。
新保留字
abstract boolean byte char decimal
double enum final float get
implements int interface internal long
package private protected public sbyte
set short static uint ulong
ushort void JScript 还有一系列新保留字。像受保护的保留字一样,这些关键字在当前版本的 JScript 内有着特殊的意义。由于向后兼容的原因,新保留字可用作标识符。一旦将新保留字用作标识符,它就失去了作为脚本中关键字的意义。将新保留字用作标识符会引起混淆,应予以避免。未来保留字
assert ensure event goto invariant
namespace native require synchronized throws
transient use volatile JScript 有一系列未来保留字,这些保留字将被建议用作 JScript 的未来扩展中的关键字。像新保留字一样,这些保留字也可以在当前版本的 JScript 中用作标识符。然而,若避免使用这些字,则在更新脚本以利用未来版本的 JScript 中的功能时会更为方便。在选择标识符时,避免选择已经是内部 JScript 对象或函数的名称(比如 String 或 parseInt)也是非常重要的
break case catch class const
continue debugger default delete do
else export extends false finally
for function if import in
instanceof new null protected return
super switch this throw true
try typeOf var while with 受保护的保留字不能用作标识符。将受保护的保留字用作标识符会在加载脚本时引起编译错误。注意 尽管“export”是一个受保护的保留字,但它没有实现方法。
新保留字
abstract boolean byte char decimal
double enum final float get
implements int interface internal long
package private protected public sbyte
set short static uint ulong
ushort void JScript 还有一系列新保留字。像受保护的保留字一样,这些关键字在当前版本的 JScript 内有着特殊的意义。由于向后兼容的原因,新保留字可用作标识符。一旦将新保留字用作标识符,它就失去了作为脚本中关键字的意义。将新保留字用作标识符会引起混淆,应予以避免。未来保留字
assert ensure event goto invariant
namespace native require synchronized throws
transient use volatile JScript 有一系列未来保留字,这些保留字将被建议用作 JScript 的未来扩展中的关键字。像新保留字一样,这些保留字也可以在当前版本的 JScript 中用作标识符。然而,若避免使用这些字,则在更新脚本以利用未来版本的 JScript 中的功能时会更为方便。在选择标识符时,避免选择已经是内部 JScript 对象或函数的名称(比如 String 或 parseInt)也是非常重要的
而且第二个按钮也工作正常呀!
add Method Internet Development Index --------------------------------------------------------------------------------Adds an element to the areas, controlRange, or options collection.Syntaxobject.add(oElement [, iIndex])
ParametersoElement Required. Object that specifies the element to add to the collection.
iIndex Optional. Integer that specifies the index position in the collection where the element is placed. If no value is given, the method places the element at the end of the collection. Return ValueNo return value.ResBefore you can add an element to a collection, you must create it first by using the createElement method.This method can be used to add elements only after the page loads.If the method is applied inline, a run-time error occurs.ExampleThis example uses the add method to insert an object into the options collection of a select object.<SELECT ID="oSelect">
<OPTION VALUE="1">One</OPTION>
</SELECT><SCRIPT>
var oOption = document.createElement("OPTION");
oSelect.options.add(oOption);
oOption.innerText = "Two";
oOption.value = "2";
</SCRIPT>
Standards InformationThis method is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 . Applies To[ Object Name ]
Platform Version
Win16:
Win32:
Windows CE:
Unix:
Mac:
Version data is listed when the mouse hovers over a link, or the link has focus.
areas, controlRange, options, SELECT
Move the mouse pointer over an element in the Applies To list to display availability information for the listed platforms. See Alsoremove
不信你把第二个button的id改为add1,第一个按钮还是错误。
function add(){
alert("add");
}
</script><body>
<form>
<input type="button" id="add1" value="Add" onClick="add()" />
</form>
<input type="button" id="add2" value="Add" onClick="add()" />input对象不能当数组对象用
两个button使用同一个id是不允许的.
<html>
<head>
<script language="javascript">
function add(){
alert("add");
}
</script>
</head>
<body>
<form>
<input type="button" id="add1" value="Add" onClick="add()" />
<input type="button" id="add2" value="Add" onClick="add()" />
</form>
</body>
</html>