javascript - jQuery 切换在我的页面中不起作用

标签 javascript jquery html

我想使用 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/

相关文章:

javascript - 在用户按下以 Bootstrap 模式提交表单后,如何显示成功消息?

javascript - 为什么从数据列表中选择一个项目时,值末尾的空格会消失?

c# - 无法设置通过 Window.Open 加载的页面标题

html - Iframe 没有控件工作,视频不播放

javascript - TextHighlighter 库的解除绑定(bind)/销毁事件

javascript - 将最后一行与 GetRangeByIndexes 结合使用 - Excel

javascript - jQuery:删除点击时可调整大小的句柄并在点击时添加它们?

php - 使用JQuery、PHP和MySQL登录数据验证问题

jquery - 在 .getJSON 函数之外调用变量?

javascript - 根据 li 类重新排序 ul