0

在我看来,我有两个单选按钮:

<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”图像。单击第二个单选按钮时,我想显示数据库中的原始图像。请一些帮助会很棒!

提前致谢。

4

1 回答 1

0

我通过使用 img 的源属性解决了这个问题:

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