【问题标题】:Why wont jQuery change() wont work with radio buttons in asp.net WebForms?为什么 jQuery change() 不能与 asp.net WebForms 中的单选按钮一起使用?
【发布时间】:2011-07-20 00:32:08
【问题描述】:

jQuery change() 不适用于我在 asp.net WebForms 中的单选按钮。

这是我尝试在我的网络表单应用程序中使用的代码的 jsFiddle 链接。

jsFiddle

我正在使用 jQuery 1.4.1

有人知道这个问题吗?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
    <script type="text/javascript">

    $(document).ready(function () {

        radiogroup = $('#radio').children('input:radio');

        $(radiogroup).change(function () {
            if ($(this).val() == 'on') {
                alert($(this).val());
                $('.timeLimit').show();
            }
            if ($(this).val() == 'off') {
                alert($(this).val());
                $('.timeLimit').hide();
            }
        });
    });
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div id="radio" class="cell ms-formbody">
        <input type="radio" value="on" id="radio1" name="radio" /><label for="radio1">On</label>
        <input type="radio" value="off" id="radio2" name="radio" checked="checked" /><label for="radio2">Off</label>
    </div>
    </form>
</body>
</html>

我花了 3 个多小时试图找出问题的原因,现在急需帮助。 :(

【问题讨论】:

  • 你能发布你的 ASP.NET 代码吗?此外,jsFiddle 正在按预期的方式工作,对吧?
  • 我会打包代码,请稍等。是的,jsFiddle 可以按我的意愿工作。
  • 我发布了一个带有相关代码的缩小版。
  • 认为您仍然缺少一些东西,没有 timeLimit 元素。
  • 是的,我注意到了一些问题。我会解决的,BRB =)

标签: jquery asp.net webforms


【解决方案1】:

问题已通过使用 jQuery 1.6.2 而不是 1.4.1 解决

【讨论】:

    猜你喜欢
    • 2017-08-25
    • 2011-02-08
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多