0

javascript 関数が呼び出されたときに、html 段落要素の 1 つのテキスト値を別の html 段落要素に渡そうとしています。この関数が呼び出されると、拡大された画像と段落コンテンツを持つ div 要素が読み込まれます。そのため、ある html 段落要素のテキスト値から別の段落要素のテキスト値に値を渡します。参考までに、以下に私のコードを示します。

Javascript:

<script type="text/javascript">
 function LoadDiv(url)
 {

    var img = new Image();
    var bcgDiv = document.getElementById("divBackground");
    var imgDiv = document.getElementById("divImage");
    var imgFull = document.getElementById("imgFull");

        img.onload = function() {
        imgFull.src = img.src;
        imgFull.style.display = "block";
        imgLoader.style.display = "none";
    };
    img.src= url;
    var width = document.body.clientWidth;
    if (document.body.clientHeight > document.body.scrollHeight)
    {
        bcgDiv.style.height = document.body.clientHeight + "px";
    }
    else
    {
        bcgDiv.style.height = document.body.scrollHeight + "px" ;
    }

    imgDiv.style.left = (width-650)/2 + "px";
    imgDiv.style.top =  "20px";
    bcgDiv.style.width="100%";

    bcgDiv.style.display="block";
    imgDiv.style.display="block";

     var artcontent = document.getElementById("TextBox2").value;
     document.getElementById("content").value = artcontent;

    /* after I added these two lines of codes below which I thought these could pass the        value but it just ruined my function and not loading anymore the div element I'm calling,it will now only flash the div element for 1 sec without event displaying the content of the artxt2 html paragraph.*/

     var artcon = document.getElementById('artxt1').innerHTML;
     document.getElementById('artxt2').innerHTML = artcon;

    return false;

 }

</script>

Asp.Net ソース コード:

<div id="divBackground" class="modal">
</div>
<div id="divImage">
    <table style="height: 100%; width: 100%">
        <tr>
            <td valign="middle" align="center">

                <img id="imgFull" alt="" src=""
                 style="display: none;
                height: 500px;width: 590px" />
            </td>
        </tr>

        <tr>
        <td >
        <p id ="artxt2" runat ="server" ></p>
        <textarea name = "artcont" id = "content" cols ="0" rows ="0" readonly ="readonly" style ="width :590px; height :100px; color :Blue; font-family :Verdana; display :block;"></textarea>  
        </td>
        </tr>

        <tr>
            <td align="center" valign="bottom">
                <input id="btnClose" type="button" value="close"
                 onclick="HideDiv()"/>
            </td>
        </tr>
    </table>
</div>

私を助けて、ここで何が欠けているかを理解してくれる人が必要です..よろしくお願いします。

4

2 に答える 2

0

これを試して -

var artcon = document.getElementById('<%=artxt1.ClientID%>').innerHTML;
document.getElementById('<%=artxt2.ClientID%>').innerHTML = artcon;

コントロールに runat=server がある場合、ID は .NET によって自動生成されます (ASP.NET 4.0 でのみ導入されたと思われる静的 ID を使用するように特に指示しない限り)。

したがって、ClientID プロパティを使用して、コントロールの生成された ID を取得する必要がありますhttp://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid.aspx

于 2013-05-16T12:52:22.943 に答える