gpt4 book ai didi

jquery - 单选按钮检查 jquery 中的条件

转载 作者:行者123 更新时间:2023-12-01 03:28:34 25 4
gpt4 key购买 nike

我有以下字段:

            <label>Company Type:</label>
<label for="primary"><input onclick="javascript: $('#sec').hide('slow');$('#primary_company').find('option:first').attr('selected','selected');" type="radio" runat="server" name="companyType" id="primary" />Primary</label>
<label for="secondary"><input onclick="javascript: $('#sec').show('slow');" type="radio" runat="server" name="companyType" id="secondary" />Secondary</label>
<div id="sec">
<fieldset>
<label for="primary_company">Primary Company:</label>
<%= Html.DropDownList("primary_company", Model.SelectPrimaryCompanies, "** Select Primary Company **") %>
</fieldset>

如果有 Primary_company,则应选择辅助单选按钮。如果没有 Primary_company,则应选择主要单选按钮。

这是我的 jQuery:

$(document).ready(function() {
if ($('#primary_company').val().length > 0) {
$('#secondary').attr({ checked: true });
}
else {
$('#primary').attr('checked', true );
$('#sec').hide();
}

第二个 div 可以正确隐藏和显示,但单选按钮从未被选中。我尝试过 .attr('checked', 'checked').attr({checked: true }).attr('checked', true) 但没有选择任何内容。

编辑我现在已经尝试了 .attr('checked', 'true')我的id可能有问题吗?我被困住了。

最佳答案

语法是:

$('#secondary').attr('已检查','true');

关于jquery - 单选按钮检查 jquery 中的条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2701553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com