这是单击单选按钮并通过“提交”按钮评估时播放音频的代码。 两个单选按钮分别有两个声音文件。通过“提交”按钮评估这些文件时,它们不会播放。请检查代码是否正常工作。
<html>
<head>
<script LANGUAGE="JavaScript">
var snd = new Audio('\Users\raja\Desktop\abs.mp3');
var x = new Audio('\Users\raja\Desktop\new.mp3');
function ValidateForm(form){
ErrorText= "";
if ( ( form.gender[0].checked == false ) && ( form.gender[1].checked == false ) )
{
alert ( "Please choose your Gender: Male or Female" );
return false;
}
if ( ( form.gender[0].checked == true ) && ( form.gender[1].checked == false ) )
{
snd.play();
alert ( "Your Gender:Male");
return false;
}
if ( ( form.gender[0].checked == false ) && ( form.gender[1].checked == true ) )
{
x.play();
alert ( "Your Gender:Female");
return false;
}
if (ErrorText= "") { form.submit() }
}
</script>
</head>
<body>
<form name="feedback" action="#" method=post>
Your Gender:
<p><input type="radio" name="gender" value="Male"> Male </p>
<p><input type="radio" name="gender" value="Female" > Female</p>
<input type="button" name="SubmitButton" value="Submit" onClick="ValidateForm(this.form)">
<input type="reset" value="Reset">
</form>
</body>
</html>