0

ダイアログウィンドウからラジオボタンを選択した場合を除いて、機能しているように見えるコードがあります。常に最初の値を選択します。このコードを php で ID (pd_id) とともに使用して、目的の結果を提供しています。

指摘してください、何が間違っているのでしょうか?この例では、ラジオ ボタンからどのオプションを選択しても、常に水が得られます。

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<style>
    body { font-size: 62.5%; }
    label, input { display:block; }
    input.text { margin-bottom:12px; width:95%; padding: .4em; }
    fieldset { padding:0; border:0; margin-top:25px; }
    h1 { font-size: 1.2em; margin: .6em 0; }
    div#users-contain { width: 350px; margin: 20px 0; }
    div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
    div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
    .ui-dialog .ui-state-error { padding: .3em; }
    .validateTips { border: 1px solid transparent; padding: 0.3em; }
</style>

<script>
    $(function() {
        var name = $("#name_34");

        $("#dialog-form-34").dialog({
            autoOpen: false,
            height: 300,
            width: 350,
            modal: true,
            buttons: {
                "Select": function() {
                    var bValid = true;
                    name.removeClass("ui-state-error");
                     //name.val("").removeClass("ui-state-error");

                  //  $("#users_34 input").append(name.val());



                    $('input[name=users_34]').val(name.val());
alert(name.val());

                    $(this).dialog("close");


                },
                Cancel: function() {
                    $(this).dialog("close");
                }
            },
            close: function() {
                name.val("").removeClass("ui-state-error");
            }
        });

        $("#spice_34")
                .button()
                .click(function() {

            $("#dialog-form-34").dialog("open");
        });
    });
</script>




<form id="dialog-form-34" title="Select Spice Level" method="post">

    <input type="radio" id="name_34" value="Water" class="text ui-widget-content ui-corner-all"> Water<br>
<input type="radio" id="name_34" value="Beer" class="text ui-widget-content ui-corner-all"> Beer<br>
<input type="radio" id="name_34" value="Wine" checked class="text ui-widget-content ui-corner-all">Wine 
</form>          


<input id="users" name="users_34" type="text "class="ui-widget ui-widget-content" readonly/>         
<button id="spice_34">Select</button>
4

1 に答える 1

1

HTML では、要素ごとに異なる ID が必要です。ラジオ ボタンで等しくする必要があるのは name です。

<input type="radio" name="yourname" value="Water" class="text ui-widget-content ui-corner-all"> Water<br>
<input type="radio" name="yourname" value="Beer" class="text ui-widget-content ui-corner-all"> Beer<br>

次に、選択した要素の値を取得するには、次のようにします。

var value = $('[name="yourname"]:checked').val();
于 2013-05-26T16:28:06.347 に答える