jquery对单选框、多选框、文本框等常见操作
2014-10-14 10:06
696 查看
jquery对单选框、多选框、文本框等常见操作
一、文本框、单选按钮、复选框、相关操作?
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>jQuery common</title> <meta name="description" content=""> <meta name="keywords" content=""> <link href="" rel="stylesheet"> <script type="text/javascript" src="jquery-1.8.3.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ //初始化下拉列表--动态添加 var item = ['幼儿园','小学','初中','高中','大学','研究生','博士','硕士']; var html ="<option value='0'>请选择</option>"; for (var i = 0;i < item.length;i++){ html += "<option value='"+(i+1)+"'>"+item[i]+"</option>"; } $("#grade").empty().append(html); $("#grade option[value='0']").attr("selected","selected");//默认第一项被选中 }) //为Select添加事件,当选择其中一项时触发 function showIt(){ var selectText = $("#grade option:selected").text();//获取Select选择的Text //var selectText = $("#grade").find("option:selected").text();//这种方式也可行 var selectValue = $("#grade").val();//获取被选择的value var selectIndex = $("#grade").get(0).selectedIndex//获取select的索引值 var text = '选择:'+selectText+"\n"; text +='value值:'+selectValue+"\n"; text +='索引值:'+selectIndex; $("#text").text(text); } </script> </head> <body> <div> <select name='grade' id='grade' onchange="showIt()"></select> <p><textarea name='text' id='text' row='30' col='100'></textarea></p> </div> </body> </html>
相关文章推荐
- jquery对单选框,多选框,文本框等常见操作小结
- jQuery获取及设置单选框、多选框、文本框内容
- jQuery获取及设置单选框、多选框、文本框内容
- jQuery获取及设置单选框、多选框、文本框内容
- jQuery获取及设置单选框、多选框、文本框内容
- jQuery对单选框、多选框的操作处理
- jQuery获取及设置单选框、多选框、文本框内容
- 使用jQuery为文本框、单选框、多选框、下拉框、下拉多选框设值及返回值的处理
- jQuery获取及设置单选框、多选框、文本框
- jQuery获取及设置单选框、多选框、文本框内容
- jQuery对下拉框,单选框,多选框的操作
- jQuery获取及设置单选框、多选框、文本框内容
- jQuery获取及设置单选框、多选框、文本框内容
- jquery操作下拉列表、文本框、复选框、单选框集合(收藏)
- jquery操作下拉列表、文本框、复选框、单选框集合(收藏)
- jQuery操作单选框、多选框是否选中问题
- 使用jQuery为文本框、单选框、多选框、下拉框、下拉多选框设值及返回值的处理
- jQuery获取及设置单选框、多选框、文本框内容
- jQuery获取及设置单选框,多选框,文本框内容