我想隱藏 div,但是當我單擊隱藏 div 時,它會再次顯示。
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Button runat="server" ID="Name" CssClass="btn" Text="Add Producd" OnClientClick="toggle()" />
<script type="text/javascript">
function toggle() {
var x = document.getElementById('Workshop');
if (x.style.display === 'none') {
x.style.display = 'block'
}
else {
x.style.display = 'none';
}
}
</script>
<div id="Workshop">
<h1 style="background-color: red">Test</h1>
</div>
</ContentTemplate>
</asp:UpdatePanel>
uj5u.com熱心網友回復:
您的 asp:Button 導致回發,導致頁面以默認顯示狀態的 div 重新加載。您可以在 OnClientClick 中禁用回發:
<asp:Button runat="server" ID="Name" CssClass="btn" Text="Add Producd" OnClientClick="toggle(); return false;" />
或者您可以使用不同的控制元件:
<input type="button" name="Name" id="Name" onclick="toggle()" class="btn" value="Add Producd" />
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/424689.html
標籤:javascript 网 网络表格
