Hide buttons based on status

Source: Internet
Author: User

Requirement Description: When entering the detail page, the button of the detail page should be judged according to the state of the object: 1 edit delete close Release 2 edit delete close 3 edit close 4 close

Solution: The default all buttons are hidden, according to state 1234, control the corresponding button's style property from hide to display,

Code:

HTML code:
<div class= "Btn-group" >
<button class= "btn sbold Green" id= "Todelete" onclick= ""style= "Display:none;">
<span class= "Ladda-label" >
<i class= "fa fa-plus" aria-hidden= "true" ></i> Delete
</span>
</button>
</div>
<div class= "Btn-group" >
<button class= "btn sbold Green" id= "torelease" onclick= ""style= "Display:none;">
<span class= "Ladda-label" >
<i class= "fa fa-plus" aria-hidden= "true" ></i> released
</span>
</button>
</div>
<div class= "Btn-group" >
<button class= "btn sbold Green" id= "Toedit" onclick= ""style= "Display:none;">
<span class= "Ladda-label" >
<i class= "fa fa-plus" aria-hidden= "true" ></i> edit
</span>
</button>
</div>
<div class= "Btn-group" >
<button class= "btn sbold Green" id= "Toclose" onclick= ""style= "Display:none;">
<span class= "Ladda-label" >
<i class= "fa fa-plus" aria-hidden= "true" ></i> off
</span>
</button>
</div>

JS code <script type= "Text/javascript" th:inline= "JavaScript" xmlns:th= "http://www.w3.org/1999/xhtml" >
var code =[[${code}]; To get the status of a background pass through
Switch (code) {
Case 1:
document.getElementById ("Torelease"). style.display= "block";//Display
document.getElementById ("Todelete"). style.display= "block";//Display
document.getElementById ("Toedit"). style.display= "block";//Display
document.getElementById ("Toclose"). style.display= "block";//Display
Break
Case 2:
document.getElementById ("Todelete"). style.display= "block";//Display
document.getElementById ("Toedit"). style.display= "block";//Display
document.getElementById ("Toclose"). style.display= "block";//Display
Break
Case 3:
document.getElementById ("Toedit"). style.display= "block";//Display
document.getElementById ("Toclose"). style.display= "block";//Display
Break
Case 4:
document.getElementById ("Toclose"). style.display= "block";//Display
Break
}
</script>

Background Java code map.addattribute ("code", code);
return View_path + "/packdetail";

Summary: In fact, other methods can be used to achieve this effect in addition

document.getElementById ("Toclose"). style.display= "Block"; Mode 1$ ("#toClose"). Parent (). CSS ("Display", "");//Mode 2

Yes, but the way 2 my own seems to be not good, the colleague's writing is absolutely no problem

Hide buttons based on status

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.