繁体   English   中英

MVC2中部分视图中的Javascript

[英]Javascript in partial view in MVC2

我在我的项目中使用MVC2。我在“ .aspx”页面中具有以下代码,该代码确定是否应显示“ .ascx”页面:

<% if(Model.MRxECG != null) { %>
                     <div id="ecg">
                        <% Html.RenderPartial("ecgDetails", Model); %>
                    </div>
                     <% } %>

这是“ .ascx”页面中的代码。

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Intranet.Models.CareRecord.CareRecordSummaryModel>" %>

<script type="text/javascript">

    function resImage(image)
    {
        var resize = 200; // amount in percentage
        var oldheight  = 150;  // height of your image
        var oldwidth  = 250; // width of your image
        var X = event.x;
        var Y = event.y;
        var newHeight   = oldheight * (resize / 100);
        var newWidth   = oldwidth * (resize / 100);

        image.style.height = newHeight;//height of new image
        image.style.width  = newWidth;// width of new image

        var c = image.parentNode;

        c.scrollLeft = (X * (resize / 100)) - (newWidth / 2) / 2; //this is for 
        c.scrollTop  = (Y * (resize / 100)) - (newHeight / 2) / 2;//new center
}
    </script>

<div>
    <table class="layout" width="900px">
        <tr>
            <td>
             <img src='<%= Url.Action("ShowMRx12LeadImage", "CareRecord", new { id = Model.CareRecord.CaseNumber}) %>'
                                                        alt="12-Lead ECG" style="width: 1000px; height: 800px;" onmouseover="resImage(this)" />
            </td>
        </tr>
    </table>
</div>

该图像不会在鼠标悬停事件上缩放。 我尝试将Javascript代码放在“ .aspx”页面中,但是那没用。 我应该怎么做才能使这项工作?

我不确定Javascript是否可以在.ascx页面中使用。是否必须使用jQuery才能实现放大功能?

image.style.height应该是具有指定尺寸(px)的字符串,而不是数字。

考虑更改这些行:

image.style.height = newHeight + 'px';//height of new image
image.style.width  = newWidth + 'px';// width of new image

有一个onmouseover的示例: http : //www.w3schools.com/jsref/tryit.asp? onmouseover = onmouseover ,您可以在这里尝试它的工作方式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM