jquery焦点事件似乎工作不正常

jquery焦点事件似乎工作不正常,jquery,html,Jquery,Html,我尝试使用jquery焦点事件处理以下内容: 搜索有三个标准,即邮政编码、城市、半径。用户可以选择单选按钮显示的单选一个 要求是,当用户单击文本框时,应选择相应的单选按钮,但该按钮似乎无法正常工作 jquery如下所示: $(".criteria input[type='text']").focus(function(){ $(".criteria input[type='radio']").attr('checked', false); $(this).parent().fi

我尝试使用jquery焦点事件处理以下内容:

搜索有三个标准,即邮政编码、城市、半径。用户可以选择单选按钮显示的单选一个

要求是,当用户单击文本框时,应选择相应的单选按钮,但该按钮似乎无法正常工作

jquery如下所示:

$(".criteria input[type='text']").focus(function(){
    $(".criteria input[type='radio']").attr('checked', false);

    $(this).parent().find("input[name='SearchRange']").attr('checked',true);
});
html如下所示

<section class="row searchgroup criteria"> 
                <section class="col-xs-12">
                    <div class="fieldgroup">
                        <input type="radio" name="SearchRange" id="PostalCode" />
                        <label for="PostalCode">Postal Code</label>
                        <input type="text" id="PostalCodeTxt" placeholder="PostalCode" /> 
                        <div class="clear">&nbsp;</div> 
                    </div>

                    <div class="fieldgroup">
                        <input type="radio" name="SearchRange" id="City" />
                        <label for="City">City</label>
                        <input type="text" id="CityTxt" placeholder="City" /> 
                        <div class="clear">&nbsp;</div>
                    </div>


                    <div class="fieldgroup">
                        <input type="radio" name="SearchRange" id="SearchRadius" />
                        <label for="SearchRadius">Search Radius</label>
                        <input type="text" id="SearchRadiusTxt" placeholder="SearchRadius" /> 
                        <div class="clear">&nbsp;</div>
                    </div>
                 </section>
            </section> <!--searchgroup-->

邮政编码
城市
搜索半径

它在前几次工作,然后没有单选按钮被选中。非常感谢您的帮助。

您需要使用设置选中的
(因为它是一个属性),而不是
attr()

使用而不是

另请访问


谢谢。。似乎正在工作……)只需补充一下,该代码在Phonegap中使用。
$(".criteria input[type='text']").focus(function(){
    $(".criteria input[type='radio']").prop('checked', false);   
    $(this).parent().find("input[name='SearchRange']").prop('checked',true);
});
$(".criteria input[type='text']").focus(function(){
    $(".criteria input[type='radio']").prop('checked', false);   
    $(this).parent().find("input[name='SearchRange']").prop('checked',true);
});