我想使用 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();
});
关于javascript - jQuery 切换在我的页面中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39964780/