jQuery表单选择器

现有以下表单:

<form>
  用户名: <input type="text"/><br>
  密 码: <input type="password"/><br>
  爱 好:
  <input type="checkbox" checked="checked"/>篮球
  <input type="checkbox" checked="checked"/>足球
  <input type="checkbox" checked="checked"/>羽毛球 <br>
  性 别:
  <input type="radio" name="sex" value='male'/><input type="radio" name="sex" value='female'/><br>
  邮 箱: <input type="text" name="email" disabled="disabled"/><br>
  所在地:
  <select>
    <option value="北京">北京</option>
    <option value="天津" selected="selected">天津</option>
    <option value="河北">河北</option>
  </select><br>
  <input type="submit" value="提交"/>
</form>

需求如下:

1. 选择不可用的文本输入框
2. 显示选择爱好 的个数
3. 显示选择的城市名称

现实现如下:

1. 选择不可用的文本输入框

$("input:disabled").css("background","red")

2. 显示选择爱好 的个数

console.log($(":checkbox:checked").length)

3. 显示选择的城市名称

console.log($("select>option:selected").html())
通过select实现
console.log($("select").val())//获得select的值
原文地址:https://www.cnblogs.com/caicaihong/p/9376159.html