<head></head>
<script>
function check(val)
{
alert(document.getElementById(val).value)
}
</script>
</head>
<body>
<input name="textfield" type="text" value="888" id="test">
</body>
<script>
check("test")
</script>
</html>
这样是可以的,你那样在还没有运行到<input name="textfield" type="text" value="888" id="test">时就调用check肯定获取不到对象啊
或者这样
<html>
<head></head>
<script defer>
function check(val)
{
alert(document.getElementById(val).value)
}
check("test")
</script>
</head>
<body>
<input name="textfield" type="text" value="888" id="test">
</body>
</html>
加上defer表示加载完文档以后才开始执行js
javascript函数中的参数对象arguments是个对象,而不是数组。但它可以类似数组那样通过数字下表访问其中的元素,而且它也有length属性标识它的元素的个数。通常我们把它转换成数组用array的slice函数,示例代码如下:functionfn()
{
var
arr
=
array.prototype.slice.call(arguments,0)
alert(arr.length)}