场景:
- 具有给定 GroupName 和
AutoPostBack="true"的多个单选按钮。
- 出于样式目的,单选按钮通过 js 隐藏,并且通过 js 处理对其容器(td)的点击
- 当点击td时,脚本会“点击”输入元素并触发asp.net的自动回发
它会回发并命中服务器上的 PageLoad,但不会触发代码隐藏中的事件。
最佳答案
我发布此内容是为了防止有人不幸遇到此问题。
对此答案的评论中非常准确地提到了问题 https://stackoverflow.com/a/8244315/66372 .
There is however one thing with the .click(): If you change the selected value of a radio with javascript like this, the 'change' event does not fire in IE (I tried IE8) – Michiel Reyers
这似乎扰乱了 ASP.NET 的回发事件处理。因此,为了让它拾取它,我们首先显式选择它:
$(this).find("input").prop("checked", true);
$(this).find("input").click();
关于javascript - 当自动回发打开时如何使用 javascript 选择 asp.net RadioButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13827190/