1

我有一个用 PHP、jQuery 和 Boostrap 编写的问卷。用户必须通过复选框或下拉菜单选择一些答案。当他们按下下一个按钮(箭头)时,系统必须检查他们是否选择了一个选项。如果没有,则会出现一条简单的消息。

    <label for="vraag1">Ik ben een...</label>
    <select name="vraag1" class="">
    <option value="">-- kies een antwoord --</option>
    <option value="antw1"<?php echo $_POST['vraag1'] == "antw1" ? " selected" : ""; ?>>Jongen</option>
    <option value="antw2"<?php echo $_POST['vraag1'] == "antw2" ? " selected" : ""; ?>>Meisje</option>
    </select>

按钮

<div class="pageNext span1"><a href="#stap3" data-toggle="tab" class="tabber"><img id="next_stap3" src="<?php echo BASEURL; ?>img/arrow-right.png" alt="Volgende pagina" title="Volgende pagina" /></a></div>

谢谢 :)

4

1 回答 1

1
$( function(){                                                          // Dom ready
    $( "#id-of-your-button" ).click( function(){                        // Trigger click in button
        if( ( $( "input[type=checkbox]:checked" ).length === 0 ) ||     // We have a checkox checked
            ( $( "select" ).val() === "" ) )                            // We have selected an option in the select?
        {
            $( "body" ).prepend( "Dude you must select something!" )    // Insert message
            return false;                                               // Prevent default behavior and bubbling in the button
        }
    } );
} );
于 2013-06-11T09:06:59.470 回答