0

我有以下html:

    <input type="text" class="searchpersontxtbox" />
    <input type="button" value="Find" class="findpersonbtn btn" disabled="disabled" />
    <img class="loader" style="display: none;" alt="Loading..." src="@Url.Content("~/Content/Images/ajax-loader.gif")" />
    <div class="peopleresultsdiv"></div>
    <div class="contactType">
        <input type="radio" name="searchtype" value="person" >Person
        <input type="radio" name="searchtype" value="organisation" checked="checked">Organisation
    </div>
<input type="text" class="searchpersontxtbox" />
    <input type="button" value="Find" class="findpersonbtn btn" disabled="disabled" />
    <img class="loader" style="display: none;" alt="Loading..." src="@Url.Content("~/Content/Images/ajax-loader.gif")" />
    <div class="peopleresultsdiv"></div>
    <div class="contactType">
        <input type="radio" name="searchtype" value="person" checked="checked">Person
        <input type="radio" name="searchtype" value="organisation">Organisation
    </div>

所以这里有两个搜索。我想知道的是当点击查找按钮时如何确定点击了哪个单选按钮?因此,如果在第一次单击查找按钮,它将是组织,如果在第二次搜索上单击查找按钮,它将是人员。

如果页面上只有一个搜索,我想我可以弄清楚如何做到这一点,但有两个搜索的事实让我感到困惑。

4

2 回答 2

0

您可以确定单击按钮的索引,然后使用 JQuery 访问具有相同索引的单选组:

$('input[type=button]').index($this)

小提琴:http : //jsfiddle.net/hd72Q/

于 2013-03-10T19:27:13.023 回答
0

如果这些是不同的搜索,那么恕我直言,您需要更改每个组中无线电输入类型的名称,否则它们就像一个组一样。所以第二次搜索可能是

<input type="radio" name="searchtype2" value="person" checked="checked">Person
<input type="radio" name="searchtype2" value="organisation">Organisation
                                    ^

这是另一种获取与您的查找按钮相关的选中单选输入类型的值的方法

$(".findpersonbtn.btn").click(function(){
    var value = $(this).nextAll(".contactType").first().find("input[type=radio]:checked").val();
    alert(value);
});

jsFiddle

于 2013-03-10T19:40:13.723 回答