0

我试图在调用 javascript 函数时将我的一个 html 段落元素的文本值传递给另一个 html 段落元素。调用此函数时,它将加载具有放大图像和段落内容的 div 元素,这就是我将值从一个 html 段落元素文本值传递到另一个段落元素文本值的原因。下面是我的代码供您参考:

Java脚本:

<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 回答
0

用 id 更改名称。

 artxt1 must be an id of a control not name.
 var artcon = document.getElementById('artxt1').innerHTML;
 document.getElementById('content').innerHTML = artcon;
于 2013-05-16T12:14:19.950 回答