function show(name,age)
{
var x=document.getElementsByTagName("radio");
function show()
{
if (x.name==="true")
{
alert("true");
}
}
}
PLZ伙伴帮忙。我遇到了问题,没有任何反应,如果单击无线电并且输入名称为真,我希望我的脚本发出警报功能
答案 0 :(得分:1)
document.getElementsByTagName
函数返回一个HTMLCollection
,一个“实时”数组,随着DOM的变化而变化。
您必须从集合中选择一个元素才能对该元素执行任何操作,因此请将private static void movieQuiz (Movies[] movieRecord){
int score = 0;
Scanner keyboard = new Scanner (System.in);
String userChoice;
System.out.println("You have selected the Movie Quiz! The instructions"
+ " are as follows: The program will output \nthe title of one of "
+ "the highest grossing films of all time, your job is "
+ "to guess which year \nit was released. A point will be added "
+ "to your score for each correct answer, and your total \npoints will"
+ " display at the end or until you want to give up. Have fun and"
+ " good luck!\n");
int test = 0;
loadMovies(movieRecord);
System.out.println("Are you ready to begin?");
userChoice = keyboard.next();
//do this if they want to run it again
do {
for (int count = 0; count <= movieRecord.length-1; count++) {
System.out.println("Movie #" + (test+1) + ": " + movieRecord[count].movieTitle);
System.out.println("Guess the year");
int guess = keyboard.nextInt();
if (guess == movieRecord[count].releaseYear){
System.out.println("DING DING DING! (+1) \n" );
score++;
}
else {
System.out.println("Wrong (+0) \n");
}
System.out.println("Continue? (Currently on #" + (1 + test) + " out of "
+ movieRecord.length + ")");
userChoice = keyboard.next();
test++;
}
} while (userChoice.charAt(0) == 'y');
//display if they type 'no' at any time, ending the program
System.out.println("Total Score is: " + score + " out of " + movieRecord.length);
System.out.println("AGAIN? yes/no?");
userChoice = keyboard.next();
}
更改为x.name
。
修改强> 我也注意到你正在搜索“radio”标签名称,但是你使用的是输入标签,因此document.getElementsByTagName调用可能无法返回你想要的标签。
你可能想要:
x[0].name