0

私の見解では、2 つのラジオボタンがあります。

<tr>
                                <td width="125">
                                    <%= Html.RadioButtonFor(m => m.IsAnonymous, false, new { onclick = "toggleAnonymity(false)" })%>
                                    <%= MyResources.AnonymousNo%>
                                </td>
                                <td width="125">
                                    <%= Html.RadioButtonFor(m => m.IsAnonymous, true, new { onclick = "toggleAnonymity(true)" })%>
                                    <%= MyResources.AnonymousYes%>
                                </td>
                            </tr>

「toggleAnonymity」関数は、クリックされたラジオボタンに応じて、ビュー内のいくつかの入力の値を有効/無効にします:

 <script language="javascript" type="text/javascript">

var firstName = "<%= Model.Name.FirstName %>";
    var middleName = "<%= Model.Name.MiddleName %>";
    var maidenName = "<%= Model.Name.MaidenName %>";
    var lastName = "<%= Model.Name.LastName %>";
    var birthDate = "<%= Model.Birthdate %>";
    var gender = "<%= (int)Model.Gender %>";

    function datePicker_OnLoad() {
        // Wait till the datepicker is loaded, this is after the window is loaded.
        // Do this because otherwise the datepicker cannot be found in the DOM.
        toggleAnonymity('<%= Model.IsAnonymous %>');
    };

    function toggleAnonymity(isAnonymous) {

        if (isAnonymous.toString().toLowerCase() == true.toString()) {

            // Store current values in variables
            // Person info
            lastName = $("#Name_LastName").val();
            maidenName = $("#Name_MaidenName").val();
            middleName = $("#Name_MiddleName").val();
            firstName = $("#Name_FirstName").val();
            birthDate = $("#Birthdate").val();
            gender = $("input:radio[name=Gender]:checked").val();

            // Clear personal info fields
            $("#Name_LastName").val('<%=CommonResources.Anonymous %>').prop('disabled', true);
            $("#Name_MaidenName").val('<%=CommonResources.Anonymous %>').prop('disabled', true);
            $("#Name_MiddleName").val('<%=CommonResources.Anonymous %>').prop('disabled', true);
            $("#Name_FirstName").val('<%=CommonResources.Anonymous %>').prop('disabled', true);
            $("#Birthdate").val('').prop('disabled', true);
            getDatePicker("#Birthdate").disable();
            $("input[name=Gender]").prop('disabled', true);

        }
        else {

            // Restore personal info values
            $("#Name_LastName").val(lastName).prop('disabled', false);
            $("#Name_MaidenName").val(maidenName).prop('disabled', false);
            $("#Name_MiddleName").val(middleName).prop('disabled', false);
            $("#Name_FirstName").val(firstName).prop('disabled', false);
            $("#Birthdate").val(birthDate).prop('disabled', false);
            getDatePicker("#Birthdate").enable();
            $("input:radio[name=Gender]").filter("[value=" + gender + "]").prop('checked', true);
            $("input:radio[name=Gender]").prop('disabled', false);              

        }
    }
</script>

それは問題ありませんが、データベースからの画像を表示する img フィールドもビューに持っています。最初のラジオボタンがクリックされたときに、ディスクから「NoImageAvailable」画像を表示したいと思います。2番目のラジオボタンをクリックすると、データベースから元の画像を表示したい。それを手伝ってください。

前もって感謝します。

4

1 に答える 1

0

imgのソース属性を使用してこれを解決しました:

$("#Picture").attr('src', 'Image.png');
于 2012-09-20T11:38:07.983 に答える