大神求助看代码,看看哪里错了。始终运行不了 JAVASCRIPT
<html><head><title></title><script>functionprintIt(){varobject1=document.getElementBy...
<html>
<head><title></title>
<script>
function printIt(){
var object1 = document.getElementById("consoles");
var object2 = document.getElementByName("CK");
var a = object1.value;
document.getElementById("S1").innerHTML = a;
if(object2[0]){
document.getElementById("S2").innerHTML = object2[0].value;
}
if(object2[1]){
document.getElementById("S3").innerHTML = object2[1].value;
}
if(object2[2]){
document.getElementById("S4").innerHTML = object2[2].value;
}
}
</script>
</head>
<body>
<form action="mailto:ziw17@pitt.edu?SUBJECT" method="post" id="myForm" name="myForm">
<select id="consoles" name="CONSOLE" value="none">
<option selected="true">XBOX</option>
<option>PS</option>
<option>WII</option>
</select>
<input type="checkbox" name="CK" id="ck1" value="Benz"/>Benz
<input type="checkbox" name="CK" id="ck2" value="Bmw"/>Bmw
<input type="checkbox" name="CK" id="ck3" value="ford"/>ford
<input type="button" onclick="printIt()"/>
<input type="reset"/>
</form>
<p>forate console: <span id="S1"></span></p>
<p>forate cars: <span id="S2"></span> <span id="S3"></span> <span id="S4"></span></p>
</body>
</html> 展开
<head><title></title>
<script>
function printIt(){
var object1 = document.getElementById("consoles");
var object2 = document.getElementByName("CK");
var a = object1.value;
document.getElementById("S1").innerHTML = a;
if(object2[0]){
document.getElementById("S2").innerHTML = object2[0].value;
}
if(object2[1]){
document.getElementById("S3").innerHTML = object2[1].value;
}
if(object2[2]){
document.getElementById("S4").innerHTML = object2[2].value;
}
}
</script>
</head>
<body>
<form action="mailto:ziw17@pitt.edu?SUBJECT" method="post" id="myForm" name="myForm">
<select id="consoles" name="CONSOLE" value="none">
<option selected="true">XBOX</option>
<option>PS</option>
<option>WII</option>
</select>
<input type="checkbox" name="CK" id="ck1" value="Benz"/>Benz
<input type="checkbox" name="CK" id="ck2" value="Bmw"/>Bmw
<input type="checkbox" name="CK" id="ck3" value="ford"/>ford
<input type="button" onclick="printIt()"/>
<input type="reset"/>
</form>
<p>forate console: <span id="S1"></span></p>
<p>forate cars: <span id="S2"></span> <span id="S3"></span> <span id="S4"></span></p>
</body>
</html> 展开
2个回答
展开全部
<html>
<head><title></title>
<script>
function printIt(){
var object1 = document.getElementById("consoles");
var object2 = document.getElementsByName("CK");
var a = object1.value;
document.getElementById("S1").innerHTML = a;
if(object2[0].checked){
document.getElementById("S2").innerHTML = object2[0].value;
}
if(object2[1].checked){
document.getElementById("S3").innerHTML = object2[1].value;
}
if(object2[2].checked){
document.getElementById("S4").innerHTML = object2[2].value;
}
}
</script>
</head>
<body>
<form action="mailto:ziw17@pitt.edu?SUBJECT" method="post" id="myForm" name="myForm">
<select id="consoles" name="CONSOLE" value="none">
<option selected="true">XBOX</option>
<option>PS</option>
<option>WII</option>
</select>
<input type="checkbox" name="CK" id="ck1" value="Benz"/>Benz
<input type="checkbox" name="CK" id="ck2" value="Bmw"/>Bmw
<input type="checkbox" name="CK" id="ck3" value="ford"/>ford
<input type="button" value="submit"onclick="printIt()"/>
<input type="reset"/>
</form>
<p>forate console: <span id="S1"></span></p>
<p>forate cars: <span id="S2"></span> <span id="S3"></span> <span id="S4"></span></p>
</body>
</html>
好了。
展开全部
<html>
<head>
<title></title>
<script>
function printIt(){
var object1 = document.getElementById("consoles");
var object2 = document.getElementsByName("CK");
var a = object1.options[object1.options.selectedIndex].text;
document.getElementById("S1").innerHTML = a;
if(object2[0].checked){
document.getElementById("S2").innerHTML = object2[0].value;
}else{
document.getElementById("S2").innerHTML = "";
}
if(object2[1].checked){
document.getElementById("S3").innerHTML = object2[1].value;
}else{
document.getElementById("S3").innerHTML = "";
}
if(object2[2].checked){
document.getElementById("S4").innerHTML = object2[2].value;
}else{
document.getElementById("S4").innerHTML = "";
}
}
</script>
</head>
<body>
<form action="mailto:ziw17@pitt.edu?SUBJECT" method="post" id="myForm" name="myForm">
<select id="consoles" name="CONSOLE" value="none">
<option selected="true">XBOX</option>
<option>PS</option>
<option>WII</option>
</select>
<input type="checkbox" name="CK" id="ck1" value="Benz"/>Benz
<input type="checkbox" name="CK" id="ck2" value="Bmw"/>Bmw
<input type="checkbox" name="CK" id="ck3" value="ford"/>ford
<input type="button" onclick="printIt()"/><input type="reset"/>
</form>
<p>forate console: <span id="S1"></span></p>
<p>forate cars: <span id="S2"></span> <span id="S3"></span> <span id="S4"></span></p>
</body>
</html>
我修改了一下你的checkbox的判断,选中的值会被打印出来。
另外,两个对象的获得方法也修改了一下。你试试看是不是你想要的,如果不是再交流。
<head>
<title></title>
<script>
function printIt(){
var object1 = document.getElementById("consoles");
var object2 = document.getElementsByName("CK");
var a = object1.options[object1.options.selectedIndex].text;
document.getElementById("S1").innerHTML = a;
if(object2[0].checked){
document.getElementById("S2").innerHTML = object2[0].value;
}else{
document.getElementById("S2").innerHTML = "";
}
if(object2[1].checked){
document.getElementById("S3").innerHTML = object2[1].value;
}else{
document.getElementById("S3").innerHTML = "";
}
if(object2[2].checked){
document.getElementById("S4").innerHTML = object2[2].value;
}else{
document.getElementById("S4").innerHTML = "";
}
}
</script>
</head>
<body>
<form action="mailto:ziw17@pitt.edu?SUBJECT" method="post" id="myForm" name="myForm">
<select id="consoles" name="CONSOLE" value="none">
<option selected="true">XBOX</option>
<option>PS</option>
<option>WII</option>
</select>
<input type="checkbox" name="CK" id="ck1" value="Benz"/>Benz
<input type="checkbox" name="CK" id="ck2" value="Bmw"/>Bmw
<input type="checkbox" name="CK" id="ck3" value="ford"/>ford
<input type="button" onclick="printIt()"/><input type="reset"/>
</form>
<p>forate console: <span id="S1"></span></p>
<p>forate cars: <span id="S2"></span> <span id="S3"></span> <span id="S4"></span></p>
</body>
</html>
我修改了一下你的checkbox的判断,选中的值会被打印出来。
另外,两个对象的获得方法也修改了一下。你试试看是不是你想要的,如果不是再交流。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询