How can I check whether a radio button is selected with JavaScript?

前端 未结 28 2412
面向向阳花
面向向阳花 2020-11-22 00:58

I have two radio buttons within an HTML form. A dialog box appears when one of the fields is null. How can I check whether a radio button is selected?

28条回答
  •  隐瞒了意图╮
    2020-11-22 01:42

    With mootools (http://mootools.net/docs/core/Element/Element)

    html:

    
    
    
    

    js:

    // Check if second radio is selected (by id)
    if ($('radiowithval2').get("checked"))
    
    // Check if third radio is selected (by name and value)
    if ($$('input[name=radiosname][value=3]:checked').length == 1)
    
    
    // Check if something in radio group is choosen
    if ($$('input[name=radiosname]:checked').length > 0)
    
    
    // Set second button selected (by id)
    $("radiowithval2").set("checked", true)
    

提交回复
热议问题