简体   繁体   English

自动切换栏位

[英]Auto toggle field

at this moment i have a field on my page that can be toggled on or off with a button. 目前,我在页面上有一个可以通过按钮打开或关闭的字段。 But i would like to have the field be automatically visible depending on what's in the field. 但是我想让该字段根据字段中的内容自动可见。 in other words, the field UserId get's the current user's id from the Xml. 换句话说,字段UserId get是Xml中当前用户的ID。 If the user id would be for example M.Bros or L. Bros, then the field should be visible, but it should be invisible for anybody else. 如果用户ID例如是M.Bros或L. Bros,则该字段应该是可见的,但对于其他任何人都应该是不可见的。

    <div id="content" style="display:block;">
        <table datasrc="#XmlUserInfo">
            <tr>
            <td style="height: 28px">UserID</td>
            <td style="height: 28px">
            <input datafld="UID" name="UserId" size="35" type="text" /></td>
            </tr>
        </table>
    </div>

<script type="text/javascript">
    function toggleContent() {
    //Get the DOM reference
    var contentId = document.getElementById("content");
    //Toggle
    contentId.style.display == "block" ? contentId.style.display = "none" :
    contentId.style.display = "block";
    }
</script>

<button onclick="toggleContent()">Toggle</button>

if you want the textbox to be visible when it has text in it then try getting the ID of the textbox, in your case UID.. 如果您希望文本框在包含文本时可见,请尝试获取文本框的ID(以您的情况为UID)。

if( UID.value == '' )UID.style.display = 'none' else UID.style.display = 'block'; if(UID.value =='')UID.style.display ='none'else UID.style.display ='block';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM