当前位置: 首页 > 图文教程 > 网络编程 > Javascript > jquery text,radio,checkbox,select操作实现代码

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 jquery text,radio,checkbox,select操作实现代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 397 ::
收藏到网摘: n/a

学习jquery的朋友看参考下,对form等文本框的一些控制实现代码。 控制表单元素:
文本框,文本区域:
$("#txt").attr("value")或者$("#txt").val()//获取值
$("#txt").attr("value",'');//清空内容
$("#txt").attr("value",'11');//填充内容
多选框checkbox:
$("#checkbox_id").attr("value")或者$("#checkbox_id").val();//获取值
$("#chk1").attr("checked",'');//不打勾
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')) //判断是否已经打勾
单选组radio:
$("input[type=radio][checked]").val();//获取值
$("input[name=tt]").attr("checked",'value2');//设置value='value2'的项目为当前选中项
$("input[name=items]").get(1).checked = true;//第二个元素为当前选中值
下拉框select:
$("select[name=topSearch] option[selected]").val();//获取值
$("select[name=topSearch] option[selected]").text();//获取显示内容
$("#sel").attr("value",'sel3');//设置value='sel3'的项目为当前选中项
$("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//添加下拉框的option
$("#sel").empty();//清空下拉框
$('#select_id')[0].selectedIndex = 1;//下拉框的第二个元素为当前选中值