【发布时间】:2017-12-26 12:08:23
【问题描述】:
我有一组 2 个 asp 无线电控件,我想在 ajax 回发中选择其中一个。我可以设置断点并且可以告诉代码正在被命中,但什么都没有发生。我已经尝试了 5-10 种不同的变体,但似乎没有任何效果。 .css 位是为了测试我是否可以找到正确的控件并且可以正常工作。 CSS 被应用。
我试过.trigger("click"),也试过attr(checked="checked" and true)。尝试了我在谷歌上能找到的任何东西。但是第二个选项没有得到检查。
$("[main=true]").Checked = true;
$("[main=true]").css("background-color", "yellow");
HTML
<asp:RadioButton GroupName="Complete" runat="server" Text="Yes" Checked="true" />
<asp:RadioButton GroupName="Complete" runat="server" Text="No" main="true" /><br />
我似乎遇到的另一个小问题是,如果我单击“是”或“否”这两个选项框,则会被取消选中。有什么理由吗?
$(window).load(function () {
$("[main=false]").prop('checked', false);
$("[main=true]").prop('checked', true);
$("[main=true]").prop('checked', true);
$("[main=true]").attr('checked', true);
$("[main=true]").Checked = true;
$("[main=true]").css("background-color", "yellow");
var id = localStorage.getItem("CustomerID");
$('img[alt = "' + id + '"]').trigger("click");
localStorage.clear();
});
HTML 输出
<span>Mark as complete:</span><span main="false">
<input id="gvCustomers_ctl07_0" type="radio" name="gvCustomers$ctl02 $Complete" value="ctl07" checked="checked" />
<label for="gvCustomers_ctl07_0">Yes</label>
</span><span main="true"><input id="gvCustomers_ctl08_0" type="radio" name="gvCustomers$ctl02$Complete" value="ctl08" />
<label for="gvCustomers_ctl08_0">No</label></span>
顺便说一句,主属性设置为 true 的单选控件不止一个,但我希望它们都被选中。不确定这是否有什么不同。没有意义的是 CSS 正在被应用。
【问题讨论】:
-
$("[main=true]").Checked = true;应该是$("[main=true]").prop('checked', true); -
也试过了,不行。
-
所以你的问题来自其他地方。我们不知道您如何尝试调用此代码。以及
<asp:RadioButton GroupName="Complete" runat="server" Text="No" main="true" />客户端是如何渲染的? -
页面加载时触发JS。我已经添加了完整的功能。
标签: javascript jquery input option