[英]jQuery toggle doesn't work in my page
I want to toggle a div with jQuery toggle function.我想用 jQuery 切换功能切换一个 div。
Here is my code:这是我的代码:
$(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>
when i click the "removeSongButton" the div togעle up and immediately toggle down.当我单击“removeSongButton”时,div 向上切换并立即向下切换。 i think maybe the page reload.
我想也许页面重新加载。
You are right, its the reload.你是对的,它的重新加载。 If the onliest thing you want to do by button-click is to toggle then add an preventDefault like this.
如果您想通过单击按钮做的最简单的事情就是切换,然后添加一个像这样的 preventDefault。 Or are there other events you want to trigger by the button-click?
或者您想通过单击按钮触发其他事件吗?
$("#removeSongButton").click(function (e) {
e.preventDefault();
$("#radioButton1").toggle();
});
Try adding div#radioButton1
as your selector.尝试添加
div#radioButton1
作为您的选择器。 I've created a super simple jsbin http://jsbin.com/rudocofowu/edit?html,output我创建了一个超级简单的jsbin http://jsbin.com/rudocofowu/edit?html,output
If that doesn't help, then I would start with removing toggle()
and try to use just slideUp()
or slideDown()
from jQuery just to isolate which one is messing up.如果这没有帮助,那么我将首先删除
toggle()
并尝试仅使用 jQuery 中的slideUp()
或slideDown()
来隔离哪个搞砸了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.