计算什么标签form.elements?
<html>
<head>
<title>
form process
</title>
<script>
function showelements()
{
var form = document.getElementById("f");
var n = form.elements.length;
alert(n);
}
</script>
</head>
<body>
<form id="f" action="#" method="post">
<p>Hello</p>
<input type="text" />
<input type="text" />
<button onclick="showelements()">Click</button>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我认为,n = 4因为有4个元素:p,input,input,button,但结果n = 3.
我的程序将文件读入字节数组,但我不知道为什么数组结果中有很多负数.我认为数组中的元素的值在0到255之间.代码在这里:
public static void main(String [] args)
{
try
{
File file = new File("C:\\1.mp3");
FileInputStream fis = new FileInputStream(file);
byte[] bytes = new byte[(int)file.length()];
fis.read(bytes);
boolean check = true;
int i = -1;
while(check)
{
i=i+1;
if(bytes[i]<0)
{
check = false;
System.out.println("There is a negative number.");
}
}
}
catch(IOException ex)
{
System.out.println(ex.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢您帮忙.
这是我的代码:
<html>
<head>
<title>Demo</title>
<script>
function show()
{
var content = document.getElementById("content");
var sub = content.getElementById("sub1");
alert(sub.nodeName);
}
</script>
</head>
<body>
<div id="content">
<div id="sub1">
Content 1
</div>
<div id="sub2">
Content 2
</div>
<input type="button" value="Click" onclick="show()" />
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
为什么content.getElementById和alert函数不起作用?谢谢你的回答.