javascript代码实例教程-jQuery表单域选择器用法分析解析教程

发布时间:2019-01-11 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-jQuery表单域选择器用法分析解析教程脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

本文实例分析jQuery表单域选择器用法。分享给大家供大家参考。具体如下:

表单域是指网页中的input,textarea, select和button元素。

1. :input选择器

代码如下:

$(":input

本文实例分析了jquery表单域选择器用法。分享给大家供大家参考。具体如下:

表单域是指网页中的input,textarea, select和button元素。

1. :input选择器

代码如下:

$(":input")

2. :text选择器

代码如下:

$(":text")

3. :password选择器

代码如下:

$(":password")

4. :radio选择器

代码如下:

$(":radio")

5. :checkbox选择器

代码如下:

$(":checkbox")

6. :file选择器

代码如下:

$(":file")

7. :image选择器

代码如下:

$(":image")

8. :hidden选择器

代码如下:

$(":hidden")

用于选择所有不可见元素(css display 属性值为none)以及隐藏域(<input tyPE="hidden">)

9. :submIT选择器

代码如下:

$(":submit")

10. :reset选择器

代码如下:

$(":reset")

简单实例:

代码如下:

<!DOCTYPE htML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">&nbsp;
<html XMlns="https://www.w3.org/1999/xhtml"> 
<head> 
<;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>表单域选择器</title> 
<script type="text/javascript" src="jquery-1.7.min.js"></script> 
<script type="text/javascript"> 
     $(document).ready(function(){ 
            $(":text").attr("value", "文本框"); 
            $(":password").attr("value", "密码框"); 
            $(":radio:eq(0)").attr("checked", "true"); 
            $(":checkbox").attr("checked", "true"); 
            $(":image").attr("src", "ICO.ICO"); 
            $(":file").css("width", "200px"); 
            $(":hidden").attr("value", "已保存的值"); 
            $("select").css("background", "#fcF");   //注意没有冒号 
            $(":submit").attr("id", "BTn1"); 
            $(":reset").attr("name", "btn"); 
            $("textarea").attr("value", "文本域");   //注意没有冒号 
         }); 
</script> 
</head> 
 
<body> 
  <table width="730" height="145" border="1"> 
  <tr> 
    <td width="113" height="23">文本框</td> 
    <td width="209"><input type="text"/></td> 
    <td width="93">密码框</td> 
    <td width="287"><input type="password" /></td> 
  </tr> 
  <tr> 
    <td height="24">单选按钮</td> 
    <td><input type="radio" /><input type="radio" /></td> 
    <td>复选框</td> 
    <td><input type="checkbox" /><input type="checkbox" /></td> 
  </tr> 
  <tr> 
    <td height="36">图像</td> 
    <td><input type="image" /></td> 
    <td>文件域</td> 
    <td><input type="file" /></td> 
  </tr> 
  <tr> 
    <td height="23">隐藏域</td> 
    <td><input type="hidden" />(不可见)</td> 
    <td>下拉列表</td> 
    <td><select><option>选项一</option><option>选项二</option><option>选项三</option></select></td> 
  </tr> 
  <tr> 
    <td height="25">提交按钮</td> 
    <td><input type="submit" /></td> 
    <td>重置按钮</td> 
    <td><input type="reset" /></td> 
  </tr> 
  <tr> 
     <td valign="top">文本区域:</td> 
     <td colspan="3"><textarea cols="70" rows="3"></textarea></td> 
  </tr> 
</table> 
</body> 
</html>

效果图如下所示:

javascript代码实例教程-jQuery表单域选择器用法分析解析教程

")

 

2. :text选择器

代码如下:

$(":text")

 

3. :password选择器

代码如下:

$(":password")

 

4. :radio选择器

代码如下:

$(":radio")

 

5. :checkbox选择器

代码如下:

$(":checkbox")

 

6. :file选择器

代码如下:

$(":file")

 

7. :image选择器

代码如下:

$(":image")

 

8. :hidden选择器

代码如下:

$(":hidden")

用于选择所有不可见元素(css display 属性值为none)以及隐藏域(<input type="hidden">)

 

9. :submit选择器

代码如下:

$(":submit")

 

10. :reset选择器

代码如下:

$(":reset")

 

简单实例:

 

代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="https://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>表单域选择器</title> 
<script type="text/javascript" src="jquery-1.7.min.js"></script> 
<script type="text/javascript"> 
     $(document).ready(function(){ 
            $(":text").attr("value", "文本框"); 
            $(":password").attr("value", "密码框"); 
            $(":radio:eq(0)").attr("checked", "true"); 
            $(":checkbox").attr("checked", "true"); 
            $(":image").attr("src", "ICO.ICO"); 
            $(":file").css("width", "200px"); 
            $(":hidden").attr("value", "已保存的值"); 
            $("select").css("background", "#FCF");   //注意没有冒号 
            $(":submit").attr("id", "btn1"); 
            $(":reset").attr("name", "btn"); 
            $("textarea").attr("value", "文本域");   //注意没有冒号 
         }); 
</script> 
</head> 
 
<body> 
  <table width="730" height="145" border="1"> 
  <tr> 
    <td width="113" height="23">文本框</td> 
    <td width="209"><input type="text"/></td> 
    <td width="93">密码框</td> 
    <td width="287"><input type="password" /></td> 
  </tr> 
  <tr> 
    <td height="24">单选按钮</td> 
    <td><input type="radio" /><input type="radio" /></td> 
    <td>复选框</td> 
    <td><input type="checkbox" /><input type="checkbox" /></td> 
  </tr> 
  <tr> 
    <td height="36">图像</td> 
    <td><input type="image" /></td> 
    <td>文件域</td> 
    <td><input type="file" /></td> 
  </tr> 
  <tr> 
    <td height="23">隐藏域</td> 
    <td><input type="hidden" />(不可见)</td> 
    <td>下拉列表</td> 
    <td><select><option>选项一</option><option>选项二</option><option>选项三</option></select></td> 
  </tr> 
  <tr> 
    <td height="25">提交按钮</td> 
    <td><input type="submit" /></td> 
    <td>重置按钮</td> 
    <td><input type="reset" /></td> 
  </tr> 
  <tr> 
     <td valign="top">文本区域:</td> 
     <td colspan="3"><textarea cols="70" rows="3"></textarea></td> 
  </tr> 
</table> 
</body> 
</html>

 

效果图如下所示:

javascript代码实例教程-jQuery表单域选择器用法分析解析教程

觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的javascript代码实例教程-jQuery表单域选择器用法分析解析教程全部内容,希望文章能够帮你解决javascript代码实例教程-jQuery表单域选择器用法分析解析教程所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。