簡體   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