Validating a radio button is checked with jQuery

前端 未结 7 1786
你的背包
你的背包 2021-01-13 07:17

On my form I havea set of radio buttons. Here\'s the mark up:

Format

7条回答
  •  一个人的身影
    2021-01-13 07:48

    Try:

    var checkbox = $("input[@name='fileType']:checked");
    
    if( checkbox.length > 0 ) {
        alert( checkbox.val() ); // checkbox value
    } else {
        alert('Please select a format'); // error
    }
    

    http://jsfiddle.net/wE4RD/

提交回复
热议问题