这是我第一次尝试 Javascript,但大约两个小时后,我无法弄清楚我犯了什么错误。我确定它很小,但我无法弄清楚为什么它在 JSFiddle 中不起作用。
这是HTML:
<form name="myForm" onsubmit="return validateForm()" method="post">
<!--Question Block One-->
Do you have a name?
<br>
Yes<input type="radio" name="first" value="yes">
No<input type="radio" name="first" value="no">
<br>
<input type="submit" value="Submit">
</form>
这是JS:
function validateForm()
{
var x=document.forms["myForm"]["first"].value;
if (x==null || x=="")
{
alert("Please answer the first question!");
return false;
}
else if (x=="yes")
{
alert("Thanks");
}
else if (x=="no"
{
alert("Sorry, we can't help");
}
}
错误:
{"error": "Shell form does not validate{'html_initial_name': u'initial-js_lib', 'form': <mooshell.forms.ShellForm object at 0x9b6da8c>, 'html_name': 'js_lib', 'html_initial_id': u'initial-id_js_lib', 'label': u'Js lib', 'field': <django.forms.models.ModelChoiceField object at 0x98e9c0c>, 'help_text': '', 'name': 'js_lib'}{'html_initial_name': u'initial-js_wrap', 'form': <mooshell.forms.ShellForm object at 0x9b6da8c>, 'html_name': 'js_wrap', 'html_initial_id': u'initial-id_js_wrap', 'label': u'Js wrap', 'field': <django.forms.fields.TypedChoiceField object at 0x9ccfe4c>, 'help_text': '', 'name': 'js_wrap'}"}
这是 JS 小提琴:http: //jsfiddle.net/4WesX/