簡體   English   中英

jQuery 切換在我的頁面中不起作用

[英]jQuery toggle doesn't work in my page

我想用 jQuery 切換功能切換一個 div。

這是我的代碼:

 $(document).ready(function () { $("#removeSongButton").click(function () { $("#radioButton1").toggle(); }); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> <asp:Button runat="server" ID="removeSongButton" Text="remove song" /> </div> <div id="radioButton1"> <asp:RadioButtonList runat="server" ID="radioButton"> <asp:ListItem Text="1" Value="1"></asp:ListItem> <asp:ListItem Text="2" Value="2"></asp:ListItem> <asp:ListItem Text="3" Value="3"></asp:ListItem> </asp:RadioButtonList > </div>

當我單擊“removeSongButton”時,div 向上切換並立即向下切換。 我想也許頁面重新加載。

你是對的,它的重新加載。 如果您想通過單擊按鈕做的最簡單的事情就是切換,然后添加一個像這樣的 preventDefault。 或者您想通過單擊按鈕觸發其他事件嗎?

$("#removeSongButton").click(function (e) {
     e.preventDefault();
     $("#radioButton1").toggle();
});

嘗試添加div#radioButton1作為您的選擇器。 我創建了一個超級簡單的jsbin http://jsbin.com/rudocofowu/edit?html,output


如果這沒有幫助,那么我將首先刪除toggle()並嘗試僅使用 jQuery 中的slideUp()slideDown()來隔離哪個搞砸了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM