访问< D​​IV>从JavaScript和code-背后 [英] Accessing <div> from both javascript and code-behind

查看:388
本文介绍了访问< D​​IV>从JavaScript和code-背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有风格=一个div显示:无。在div应成为$ P $可见pssing的HTML按钮:

I have a div with style="display:none". The div should become visible on pressing an html button:

function JSAdd() {
    document.getElementById('divDetail').style.display = "block";
}
    <div style="float:left">

    <div id="ctl00_MainContent_upnlLbRD">





            <select size="4" name="ctl00$MainContent$lbRD" id="ctl00_MainContent_lbRD" style="width:188px;">

    <option value="5">one</option>
    <option value="1">two</option>
</select>

    <input id="btnAdd" type="button" value="Добавить" onclick="JSAdd();" />
    <input id="btnEdit" type="button" value="Редактировать" onclick="JSEdit();" />
</div>
<div id="ctl00_MainContent_divDetail" style="display:none" clientidmode="static">
    <div id="ctl00_MainContent_upnlDescription">

            <div>

                <span id="ctl00_MainContent_lblDescription">Описание:</span>

                <input name="ctl00$MainContent$txtDescription" type="text" id="ctl00_MainContent_txtDescription" />  

                <span id="ctl00_MainContent_txtDescriptionRequiredFieldValidator" style="color:Red;visibility:hidden;">Описание является обязательным для заполнения</span>

            </div>

            <input type="submit" name="ctl00$MainContent$btnSave" value="Сохранить" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$MainContent$btnSave&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="ctl00_MainContent_btnSave" />   


    

我需要能够使DIV从code-再度落后无形。除非是 =服务器我无法访问股利。但是,当我添加=服务器,在div不会成为$ P $从上面的javascript函数pssing按钮可见。能否请你帮我这个?

I need to be able to make the div invisible again from code-behind. I cannot access the div unless it is runat="server". But when I add runat="server", the div doesn't become visible on pressing the button from the javascript function above. Could you please help me with this?

谢谢,结果
大卫

Thanks,
David

推荐答案

您可以通过添加访问$ C $一个div C-背后的 =服务器属性。添加此属性不会改变你的访问,虽然在JavaScript中元素的方法:

You can access a div in code-behind by adding the runat="server" attribute. Adding this attribute does change the way you access the element in JavaScript though:

var el = document.getElementById("<%=div1.ClientID%>");
if (el){
    el.style.display = "none"; //hidden
}

有两种方法来调整从code-背后的知名度,但因为你设置显示:无在JavaScript中,你可能想使用同样的方法code-背后:

There are two ways to adjust the visibility from code-behind, but since you're setting display:none in JavaScript, you'd probably want to use the same approach in code-behind:

div1.Style["display"] = "block"; //visible

在code-的背后,你还可以设置可见属性设置为false,但这是不同的,因为它会prevent从所呈现的元素在所有。

In code-behind, you can also set the Visible property to false, but this is different because it will prevent the element from being rendered at all.

修改

如果在div仍与显示显示:无 present,你可能有一个未关闭标签或引用某个地方影响的标记。仔细检查并确保该标记是有效的。

If the div is still showing with display:none present, you probably have an unclosed tag or quote somewhere affecting the markup. Double check and make sure that the markup is valid.

这篇关于访问&LT; D​​IV&GT;从JavaScript和code-背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆