如何在javascript中处理局部视图元素

时间:2013-06-27 09:16:21

标签: javascript asp.net-mvc-4 razor asp.net-mvc-partialview textchanged

请参阅此代码,它是用于使用mvc开发的Web应用程序的部分视图。

@model PortalModels.WholeSaleModelUser
    @using (Html.BeginForm("uploadFile", "WholeSaleTrade", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        @Html.ValidationSummary(true)

    <fieldset>
        <legend>WholeSaleModelUser</legend>
        <table>
            <tr>
                <td>
                    <div class="editor-label">
                        @Html.LabelFor(model => model.Name)
                    </div>
                </td>
                <td>
                    <div class="editor-field">
                        @Html.TextBoxFor(model => model.Name)
                        @Html.ValidationMessageFor(model => model.Name)
                    </div>
                </td>
            </tr>
</table>
        <div id="partial">
            <table>
                <tr>
                    <td>
                        <img id="blah" src="../../Images/no_image.jpg" alt="your image" height="200px" width="170px" />
                    </td>
                </tr>
</table>

    <script type="text/javascript">
        function loadUserImage() {
            var userImg = document.getElementById("blah");
            var imgNm = $("#Name").value;
            userImg.src = "D:/FEISPortal/FortalApplication/Img/" + imgNm + ".png";
            alert(imgNm);
            alert(userImg.src);
        }
    </script>

我需要使用上面提到的javascript代码在局部视图中处理此文本框的 textchange 事件

@Html.TextBoxFor(model => model.Name)

请有人告诉我如何处理文本框上面代码行的文本更改事件..

1 个答案:

答案 0 :(得分:0)

$document.on('blur', 'TextBox', function(){
    //Do something
});

此格式适用于局部视图上的任何字段。从这里http://api.jquery.com/on/