嵌入标签和表单元素的javascript问题 [英] javascript problem with embed tag and form elements

查看:50
本文介绍了嵌入标签和表单元素的javascript问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些javascript可以检查答案是否正确。当问题被问到文本时工作正常,但现在我用音频问这个问题,javascript不再有效。 (我认为它正在考虑将embed标签作为我表单中的一个元素,我认为这会导致问题。)我认为添加和指定只查看表单中的div标签可以解决问题,但我''我不确定。有人可以检查一下,看看你是否有解决方案?


//这会检查答案是否正确(当问题在文本中输入时工作正常但在问题时不再有效被问到音频)。


[HTML] var score = 0;

var answer = new Array(" pass"," brag", 拖动,开始,其他,保持,感觉,保持,气味);


功能检查()
for(i = 0; i< answer.length; i ++){

//answer.lenght是答案数组的长度

if(document.myform.inputs [i] .value.toLowerCase()== answer [i]){


得分++;

var p = i + 1;


var str =" showpicture" + p;

var str2 =" showwrong" + p ;

var score2 =得分/ 9 * 100

var percentage = score2.toFixed(0)+''%'';

文件.getElementById(str).style.visibility =" vis ible" ;;

document.getElementById(str2).style.visibility =" hi dden";

document.myform.score.value =得分;

document.myform.percentage.value = percentage;

document.myform.time.value = getLessonTime();

document.myform.time.value = getLessonTime() ;


}


其他


{


if(document.myform.elements [i] .value!=""){


document.myform.elements [i] .value ="再试一次 ;


var p = i + 1;


var str =" showpicture" + p;

var str2 =" showwrong" + p;


document.getElementById(str).style.visibility =" hid den";

document.getElementById (str2).style.visibility =" vi sible";

}}}


得分= 0;


}


//继承人表格的开头(我认为嵌入标签导致问题)


<表格命名= [我的形式"方法= QUOT;交" action ="< cfoutput> #CurrentPage#?#CGI.QUERY_STRING#< / cfoutput>" onSubmit =" return validateForm(this)""

< p>& nbsp;< / p>

< p align ="右" class =" smalltext">活动#2019< / p>

< table border =" 1"对齐= QUOT;中心" CELLPADDING = QUOT; 5英寸CELLSPACING = QUOT 1 QUOT; BORDERCOLOR ="#D5CCBB" bgcolor ="#000000">

< tr>

< td width =" 200" BGCOLOR = QUOT;#00FF00" class =" bigtext">< div align =" center">问题< / div>< / td>

< td width =" 100" BGCOLOR = QUOT;#00FF00" class =" bigtext">< div align =" center">答案< / div>< / td>

< td width =" 100" BGCOLOR = QUOT;#00FF00" class =" bigtext">< div align =" center"> Feedback< / div>< / td>

< / tr>

< tr>

< td bordercolor ="#D5CCBB" BGCOLOR = QUOT;#FFFF00" class =" bigbluetext">< p>< span class =" previewDiv" style =" WIDTH:240px;高度:27px">

< embed name ="" SRC =" ../媒体/ spellingwords / 1.MP3"宽度= QUOT; 240"高度= QUOT; 27"类型= QUOT;音频/ X-WAV" alt ="点击播放按钮可听到单词。自动播放= QUOT假QUOT;控制器= QUOT;真"环路= QUOT假QUOT; /> < /嵌入>

< / span>< / p> < / td>

< td bordercolor ="#D5CCBB" bgcolor =" #FFFF00">< label>< div>

< input type =" text"名称= QUOT 1 QUOT;大小= QUOT; 8英寸的onblur = QUOT;检查()" />

< / label>< / td>

< td bgcolor ="#FF0000">

< ; img src =" ../ images / generalimages / star.gif" ALT ="正确"宽度= QUOT; 48英寸;高度= QUOT; 44" ID = QUOT; showpicture1"风格= QUOT;能见度:隐藏;" />< img src =" ../ images / generalimages / blackx.gif" ALT ="错误"宽度= QUOT; 48英寸;高度= QUOT; 44" ID = QUOT; showwrong1"风格= QUOT;能见度:隐藏;" />< / td> [/ HTML]

I have some javascript that checks whether or not an answer is correct. It was working fine when the question was asked with text but now that I''m asking the question with audio, the javascript no longer works. (I think it is considering the embed tag as an element in my form and I think that''s causing the problem.) I think adding and specifying to only look at a div tag within the form would solve the problem but I''m not sure. Can someone check this out and see if you have a solution?

//this checks whether the answer is correct (worked fine when question was typed in text but no longer works when the question is asked with audio).

[HTML]var score = 0;
var answer = new Array("pass","brag","drag","began","else","held"," felt","kept","smell");

function check(){

for(i=0;i<answer.length;i++){
//answer.lenght is the lenght of the answer array
if(document.myform.inputs[i].value.toLowerCase()==answer[i]){

score++;
var p=i+1;

var str="showpicture"+p;
var str2="showwrong"+p;
var score2=score/9*100
var percentage=score2.toFixed(0) + ''%'';
document.getElementById(str).style.visibility="vis ible";
document.getElementById(str2).style.visibility="hi dden";
document.myform.score.value=score;
document.myform.percentage.value=percentage;
document.myform.time.value=getLessonTime();
document.myform.time.value=getLessonTime();

}

else

{

if(document.myform.elements[i].value!=""){

document.myform.elements[i].value="Try Again";

var p=i+1;

var str="showpicture"+p;
var str2="showwrong"+p;

document.getElementById(str).style.visibility="hid den";
document.getElementById(str2).style.visibility="vi sible";
}}}

score = 0;

}

//heres the beginning of the form (I think the embed tag is causing the problem)

<form name="myform" method="post" action="<cfoutput>#CurrentPage#?#CGI.QUERY_STRING# </cfoutput>" onSubmit="return validateForm(this)"">
<p>&nbsp;</p>
<p align="right" class="smalltext">Activity # 2019 </p>
<table border="1" align="center" cellpadding="5" cellspacing="1" bordercolor="#D5CCBB" bgcolor="#000000">
<tr>
<td width="200" bgcolor="#00FF00" class="bigtext"><div align="center">Problem</div></td>
<td width="100" bgcolor="#00FF00" class="bigtext"><div align="center">Answer</div></td>
<td width="100" bgcolor="#00FF00" class="bigtext"><div align="center">Feedback</div></td>
</tr>
<tr>
<td bordercolor="#D5CCBB" bgcolor="#FFFF00" class="bigbluetext"><p><span class="previewDiv" style="WIDTH: 240px; HEIGHT: 27px">
<embed name="" src="../media/spellingwords/1.mp3" width="240" height="27" type="audio/x-wav" alt="Click play button to hear word." autoplay="false" controller="true" loop="false" /> </embed>
</span></p> </td>
<td bordercolor="#D5CCBB" bgcolor="#FFFF00"><label><div>
<input type="text" name="1" size="8" onBlur="check()" />
</label></td>
<td bgcolor="#FF0000">
<img src="../images/generalimages/star.gif" alt="Correct" width="48" height="44" id="showpicture1" style="visibility:hidden;" /><img src="../images/generalimages/blackx.gif" alt="Wrong" width="48" height="44" id="showwrong1" style="visibility:hidden;" /></td>[/HTML]

推荐答案

为什么不直接访问表单元素而不是元素数组?

PS。更改了主题标题。
Instead of the elements array, why not access the form elements directly?

PS. changed the thread title.


谢谢,因为我的表单有九个字段,我是否必须单独调用每个字段,或者还有一些方法可以使它与数组一起工作,如果所以,你介意给我看看会是什么样的吗?谢谢acoder,我真的很感谢你的帮助!我在这方面做得越来越好但是javascript对我来说是一个艰难的学习...


Thanks, since my form has nine fields, would I have to call up each field separately or is there still some way to make it work with an array, and if so, would you mind showing me what that would look like? Thanks "acoder," I really appreciate all of your help! I''m getting better at this but javascript has been a tough one for me to learn...



而不是元素数组,为什么不直接访问表单元素?


PS。改变了主题标题。
Instead of the elements array, why not access the form elements directly?

PS. changed the thread title.


Acoder,


我不明白的是我的原始代码在Firefox中工作正常但是它在IE中不起作用。我尝试做一些改动,但在IE中仍然没有运气。

感谢您提供的任何想法。
Acoder,

What I don''t understand is that my original code works fine in Firefox but it doesn''t work in IE. I tried making some changes but still no luck in IE.
Thanks for any ideas you can give me.


这篇关于嵌入标签和表单元素的javascript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆