我正在努力让几个 javascripts 脚本正常工作。
第一个是文本框上的简单验证脚本。它工作一次,但如果您第二次点击提交,您无需输入任何内容即可继续。每次单击提交按钮时,如何使脚本触发(并工作)?
我要做的第二件事是让一个 div 类根据单选 click 进行更改。问题在于,因为所有单选按钮共享相同的 ID/名称,所以无论单击哪个单选按钮,它总是会更改第一个单选按钮背景。如何让它改变包含它的 div 的类?
HTML看起来像(在head标签中带有javascript,如图所示......
<head>
<link href="/css/0051.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function validateForm() {
var x=document.forms["form"]["txtbox_1501"].value;
if (x==null || x=="" || x=="Please type your answer in this box")
{
document.getElementById("txtbox_container").id = "txtbox_err";
document.getElementById("ques_txt").className = "ques_txt_err";
document.getElementById("ques_inst").className = "ques_inst_err";
return false;
}
}
function radioDiv() {
document.getElementById("radio_label").className = "radio_input_selected";
}
</script>
</head>
<body>
<form id="form" name ="form" action="/php/process.php" onsubmit="return validateForm()" method="post">
<div id="txtbox_container">
<div id="ques_container">
<a id="ques_txt" class="ques_txt">Please tell us your name:</br></a>
<a id="ques_inst" class="ques_inst">(How you would like to be referred to in this demo)</br></a>
</div>
<div id="txtbox_input">
<input type="text" name="txtbox_1501" value="Please type your answer in this box" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;" /></br>
</div>
</div>
<div id="radio_container">
<div id="ques_container">
<a class="ques_txt">What is your gender?</br></a>
<a class="ques_inst">(Are you female or male?)</br></a>
</div>
<label>
<div id="radio_label" class="radio_input">
<input type="radio" name="radio_1503" value="2" onclick="return radioDiv()" />
<a class="radio_label">Female</a>
</div>
</label>
<label>
<div id="radio_label" class="radio_input">
<input type="radio" name="radio_1503" value="1" onclick="return radioDiv()" />
<a class="radio_label">Male</a>
</div>
</label></div>
</div>
<div id="button">
<input type="submit" class="submitbutton" value=""/>
</div>
</form>
</body>
任何建议将不胜感激。谢谢。