访问单选按钮的 OnChange javascript 事件时出现问题

发布于 2024-08-08 21:57:46 字数 786 浏览 4 评论 0原文

我遇到了同样的问题此人有。具体来说,我正在尝试获取客户端 onchange javascript 事件来触发我的单选按钮。不幸的是,代码是通过位于单选按钮周围的跨度上而不是单选按钮本身上的 onchange 进行渲染的。

我在页面中使用其他 JavaScript 来操作单选按钮,因此 onclick 不能完全满足我的需求。

此外,在上面的链接中向用户提供的答案是“太糟糕了,请使用 html 复选框”。对于我的应用程序来说,这是低于标准的,因为我需要单选按钮来引发服务器端的 OnCheckedChange 事件。

我尝试采用的一种解决方案路径(使用 jQuery 1.1.3.1)是自己设置更改事件:

jQuery("input:radio").change(new function() { 
  setParent(jQuery(this)); 
  showUndo(jQuery(this)); 
});

这反映了 onclick 事件(当前已实现,我正在尝试将其转换为onchange ;) )

onclick="setParent(this); showUndo(this);"

但这不起作用。 :'(

I'm running in to the same problem this individual has. Specifically, I'm trying to get a clientside onchange javascript event to fire for my Radio Button. Unfortunately, the code gets rendered with the onchange located on a span surrounding the radio button instead of on the radio button itself.

I am using other javascript within the page to manipulate the radio buttons, so onclick doesn't fully satisfy my needs.

Additionally, the answer that was given to the user in the link above was "too bad, use an html check box". For my application, this is sub-par as I need the radio button to raise the OnCheckedChange event serverside.

One solution path I was attempting to go down (using jQuery 1.1.3.1) was to set the change events myself:

jQuery("input:radio").change(new function() { 
  setParent(jQuery(this)); 
  showUndo(jQuery(this)); 
});

Which mirrors the onclick event (which is currently implemented and I'm trying to convert to the onchange ;) )

onclick="setParent(this); showUndo(this);"

This didn't work, though. :'(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

翻身的咸鱼 2024-08-15 21:57:46

以下内容按预期对我有用。如果单选按钮发生更改,则会触发该事件,并且 onchange 事件处理程序中的“this”指向单选按钮对象。

    <div id="test">
        <input type="radio" name="something"/>
        <input type="radio" name="something"/>
    </div>

    <script type="text/javascript">
        $(document).ready(function() {
            $(":radio").change(function() {
                alert(this.name + ' changed');
            });
        });
    </script>

这能解决您的问题吗?

The following works for me as expected. The event fires if the radio is changed, and 'this' in the onchange event handler points to the radio button object.

    <div id="test">
        <input type="radio" name="something"/>
        <input type="radio" name="something"/>
    </div>

    <script type="text/javascript">
        $(document).ready(function() {
            $(":radio").change(function() {
                alert(this.name + ' changed');
            });
        });
    </script>

Does this solve your problem?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文