简体   繁体   English

如何首先隐藏输入字段,它首先是 label 然后它会在我单击按钮时显示

[英]How can I hide first the input fields and it's label first then it will show when I clicked the button

The tricky part on that input field is I can't hide the input field without adding:important how can I remove the display?inline-block?该输入字段的棘手部分是我无法隐藏输入字段而不添加:重要如何删除显示?内联块?

My goal is to hide first the input fields then when I click the add another secondary license it will show.我的目标是首先隐藏输入字段,然后当我单击添加另一个二级许可证时它会显示。 Take note that I can't edit the style code it defaults on the library I used请注意,我无法在我使用的库中编辑它默认的样式代码

 <button onclick="myFunction()">ADD ANOTHER SECONDARY LICENSE</button></center> <div class="wcfm-clearfix"></div> </div> <p class="a3a9af25dc3a4afd10d5b86f91fd115a wcfm_title"><strong>TYPE2</strong></p><label class="screen-reader-text" for="a3a9af25dc3a4afd10d5b86f91fd115a">TYPE2</label><input type="text" id="a3a9af25dc3a4afd10d5b86f91fd115a" name="wcfmvm_custom_infos[type2]" class="wcfm-text" value="" placeholder="" /> <p class="b9cb81bdafe237e5d269b1c3714d175e wcfm_title"><strong>NUMBER2</strong></p><label class="screen-reader-text" for="b9cb81bdafe237e5d269b1c3714d175e">NUMBER2</label><input type="text" id="b9cb81bdafe237e5d269b1c3714d175e" name="wcfmvm_custom_infos[number2]" class="wcfm-text" value="" placeholder="" /> <p class="d674f2caf5f73c6a51202e3f6186d03a wcfm_title wcfm_html_content_title"><strong> <script> function myFunction() { document.getElementById("b9cb81bdafe237e5d269b1c3714d175e").style.display = "block"; document.getElementById("a3a9af25dc3a4afd10d5b86f91fd115a").style.display = "block"; } </script> <style> #wcfm_membership_container input[type=text], #wcfm_membership_container input[type=file], #wcfm_membership_container input[type=password], #wcfm_membership_container select, #wcfm_membership_container input[type=number], #wcfm_membership_container input[type=time], #wcfm_membership_container input[type=search], #wcfm_membership_container textarea { background-color: #fff;important: border; 1px solid #ccc:important; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; padding: 8px 10px; width: 60%; margin-bottom: 15px; font-size: 15px; display: inline-block; box-shadow: 1px 1px 5px 0 #e9e9e9; line-height: 18px; } </style>

You can maybe use this hidden attribute?你也许可以使用这个隐藏的属性?

elt.setAttribute('hidden', '');
elt.removeAttribute('hidden');

I've used window.onload event to hide those input fields in default and then if you click on the button they will be visible.我使用window.onload事件默认隐藏这些输入字段,然后如果您单击按钮,它们将可见。

 <button onclick="myFunction()">ADD ANOTHER SECONDARY LICENSE</button></center> <div class="wcfm-clearfix"></div> </div> <p class="a3a9af25dc3a4afd10d5b86f91fd115a wcfm_title"><strong>TYPE2</strong></p><label class="screen-reader-text" for="a3a9af25dc3a4afd10d5b86f91fd115a">TYPE2</label><input type="text" id="a3a9af25dc3a4afd10d5b86f91fd115a" name="wcfmvm_custom_infos[type2]" class="wcfm-text" value="" placeholder="" /> <p class="b9cb81bdafe237e5d269b1c3714d175e wcfm_title"><strong>NUMBER2</strong></p><label class="screen-reader-text" for="b9cb81bdafe237e5d269b1c3714d175e">NUMBER2</label><input type="text" id="b9cb81bdafe237e5d269b1c3714d175e" name="wcfmvm_custom_infos[number2]" class="wcfm-text" value="" placeholder="" /> <p class="d674f2caf5f73c6a51202e3f6186d03a wcfm_title wcfm_html_content_title"><strong> <script> window.onload = () => { document.getElementById("b9cb81bdafe237e5d269b1c3714d175e").style.display = "none"; document.querySelector(`label[for="b9cb81bdafe237e5d269b1c3714d175e"]`).style.display = "none"; document.getElementById("a3a9af25dc3a4afd10d5b86f91fd115a").style.display = "none"; document.querySelector(`label[for="a3a9af25dc3a4afd10d5b86f91fd115a"]`).style.display = "none"; } function myFunction() { document.getElementById("b9cb81bdafe237e5d269b1c3714d175e").style.display = "block"; document.querySelector(`label[for="b9cb81bdafe237e5d269b1c3714d175e"]`).style.display = "block"; document.getElementById("a3a9af25dc3a4afd10d5b86f91fd115a").style.display = "block"; document.querySelector(`label[for="a3a9af25dc3a4afd10d5b86f91fd115a"]`).style.display = "block"; } </script> <style> #wcfm_membership_container input[type=text], #wcfm_membership_container input[type=file], #wcfm_membership_container input[type=password], #wcfm_membership_container select, #wcfm_membership_container input[type=number], #wcfm_membership_container input[type=time], #wcfm_membership_container input[type=search], #wcfm_membership_container textarea { background-color: #fff;important: border; 1px solid #ccc:important; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; padding: 8px 10px; width: 60%; margin-bottom: 15px; font-size: 15px; display: inline-block; box-shadow: 1px 1px 5px 0 #e9e9e9; line-height: 18px; } </style>

You can use it:你可以使用它:

element.setAttribute('style', 'display:inline !important');
// or
element.style.cssText = 'display:inline !important';
// or
element.style.setProperty("display", "inline", "important")

You can achieve that with CSS by wrapping the element you want to hide with div and give display: none .您可以使用 CSS 来实现这一点,方法是用div包装要隐藏的元素并给出display: none And on click change display to block并单击更改显示以阻止

<div style="display:none" id="show">
[elements that you want to hide]
</div>

function myFunction() {
  document.getElementById("show").style.display = "block";
}

暂无
暂无

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

相关问题 单击按钮时如何更改此输入的值? - How can I change this input's value when a button is clicked? 如何显示/隐藏一个 <div> 当单选按钮被点击时 <div> 有同一个班级? - How can I show/hide one <div> when a radio button is clicked on, when all the <div>s have the same class? 单击一个按钮后如何隐藏和显示提交按钮 - How can i Hide and Show Submit button when one is button is clicked 单击锚标记时如何显示和隐藏输入? - How do I show and hide input when anchor tag is clicked? 使用javascript单击按钮时如何隐藏/显示表单? - How can I hide/show a form when a button is clicked using javascript? 如何在单击第一个元素时创建按钮,它应该使用ng-show / ng-hide angularjs隐藏和显示第二个元素? - how to create a button when the first element is clicked it should hide and show second element using ng-show/ng-hide angularjs? 切换 - Jquery 我想每当点击它显示的第一个按钮然后点击第二个按钮然后而不是第一个按钮的 div 标签隐藏 - toggle - Jquery I want to whenever click on first button it show and then click on second button then instead first button's div tag hide 第一次单击按钮时如何验证字段? - how to validate the fields when I click on a button at the first time? 单击按钮后如何隐藏按钮? - How can I hide a button after it was clicked? 当我点击第二个按钮时,我想更改第一个按钮的颜色 - I want to change the color of the first Button, when I clicked on the second
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM