1

プロジェクトで 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>

画像はマウスオーバー イベントでズームしません。「.aspx」ページに Javascript コードを配置しようとしましたが、うまくいきませんでした。これを機能させるにはどうすればよいですか?

JavaScript が .ascx ページで機能するかどうかわかりません。ズームイン機能を実現するには、jQuery を使用する必要がありますか?

4

1 に答える 1

0

image.style.height、数値ではなく、指定された次元 (px) の文字列である必要があります。

次の行を変更することを検討してください。

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

http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onmouseoverのサンプルがありonmouseoverます。ここでどのように機能するかを試すことができます。

于 2013-09-19T03:31:25.333 に答える