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