-2

我有这样的html

  <input type="radio" name="Gander" value="M" id="Male" />Male
  <input type="radio" name="Gander" value="F" id="Female" /> FeMale


 <select name="DropDownList1" id="DropDownList1">
    <option value="1">PHP</option>
    <option value="2">ASP.NET</option>
    <option value="3">C SHARP</option>
    <option value="4">SQL SERVER</option>
    <option value="5">WCF</option>
</select>

我想使用 jquery 来知道选择了什么单选按钮以及在 dropdownlist1 中选择了什么选项标签并将值存储在变量中

//"the value attribute of radio button user selected"

var Gander = ??

 //"the value attr of option that user selected"

var CourseID = ??
4

3 回答 3

3
var Gander = $('input:radio[name=Gander]:checked').val();

var CourseID = $('#DropDownList1').val();
于 2012-05-08T01:50:43.507 回答
2
var Gander = $('input[type="radio"]:checked'),
    CourseID = $("#DropDownList1").val();

小提琴

于 2012-05-08T01:55:40.320 回答
1

你会使用$('input:radio:checked')$('#myId:selected')

于 2012-05-08T01:49:51.083 回答