使用警报框验证单选按钮,以便它可以被接受或拒绝 [英] Validating Radio Buttons with an alert box so it can be either accepted or rejected

查看:157
本文介绍了使用警报框验证单选按钮,以便它可以被接受或拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的学校工作,我必须在表单中添加一组单选按钮以接受GCSE,AS或A2等条目。然后,我必须编写一个javascript函数,在警告框中显示用户的输入级别,以便可以确认或拒绝该级别。到目前为止,我已经完成了单选按钮,但不知道如何执行该功能。

For my school work I have to add a set of radio buttons to the form to accept a level of entry such as GCSE, AS or A2. Then I have to write a javascript function that displays the level of entry to the user in an alert box so that the level can be confirmed or rejected. So far I have done the radio buttons but don't know how to do the function.

继承人我的代码到目前为止: http://jsbin.com/hibutazide/1/edit?html,js,output

Heres my code so far: http://jsbin.com/hibutazide/1/edit?html,js,output

推荐答案

您可以为每个单选按钮赋予不同的id,然后在javascript中使用 checked 属性。

you could give different id to every radio button, and then use checked property of them in javascript.

if(!document.getElementById('r1').checked && 
    !document.getElementById('r2').checked && 
    !document.getElementById('r3').checked){
 alert("you must choose a radio button");
}

这篇关于使用警报框验证单选按钮,以便它可以被接受或拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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