jQuery radio取值,checkbox取值,select取值\n\n语法解释:\n\n\n\n$(\#select_id\).change(function(){//code...}); //为Select添加事件,当选择其中一项时触发\nvar checkText=$(\#select_id\).find(\option:selected\).text(); //获取Select选择的Text
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body onselectstart='return false'>
<table oncontextmenu=return(false) border="1">
<tr><td>1111111111111111</td></tr>
</table>
22222222222222222222222222222
<br>
<input type=text name="" value="123" onpaste="return false" oncopy="return false;" oncut="return false;">
</body>
</html>
<script src="./jquery.js"></script>
<script>
oncontextmenu='window.event.returnValue=false';
</script>
oncontextmenu="window.event.returnValue=false"
<body onselectstart="return false">
onpaste="return false"
oncopy="return false;" oncut="return false;"
========================================================================================================================
语法解释:
$("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发
var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的Text
var checkValue=$("#select_id").val(); //获取Select选择的Value
var checkIndex=$("#select_id ").get(0).selectedIndex; //获取Select选择的索引值
var maxIndex=$("#select_id option:last").attr("index"); //获取Select最大的索引值
语法解释:
$("#select_id ").get(0).selectedIndex=1; //设置Select索引值为1的项选中
$("#select_id ").val(4); //设置Select的Value值为4的项选中
$("#select_id option[text='jQuery']").attr("selected", true); //设置Select的Text值为jQuery的项选中
语法解释:
$("#select_id").append("<option value='Value'>Text</option>"); //为Select追加一个Option(下拉项)
$("#select_id").prepend("<option value='0'>请选择</option>"); //为Select插入一个Option(第一个位置)
$("#select_id option:last").remove(); //删除Select中索引值最大Option(最后一个)
$("#select_id option[index='0']").remove(); //删除Select中索引值为0的Option(第一个)
$("#select_id option[value='3']").remove(); //删除Select中Value='3'的Option
$("#select_id option[text='4']").remove(); //删除Select中Text='4'的Option
var item = $('input[@name=items][@checked]').val();
var item = $("select[@name=items] option[@selected]").text()
$('#select_id')[0].selectedIndex = 1;
$('input[@name=items]').get(1).checked = true;
获取值:
文本框,文本区域:$(“#txt”).attr(“value”); 多选框checkbox:$(“#checkbox_id”).attr(“value”); 单选组radio: $(“input[@type=radio][@checked]”).val(); 下拉框select: $(‘#sel’).val();
文本框,文本区域:
$("#txt").attr("value",'');//清空内容
$("#txt").attr("value",'11');//填充内容
多选框checkbox:(“#chk1”).attr(“checked”,”);//不打勾<script type="math/tex" id="MathJax-Element-1">(“#chk1”).attr(“checked”,”);//不打勾
</script>(“#chk2”).attr(“checked”,true);//打勾
if((“#chk1”).attr(‘checked’)==undefined) //判断是否已经打勾
单选组radio:<script type="math/tex" id="MathJax-Element-2">(“#chk1”).attr(‘checked’)==undefined) //判断是否已经打勾
单选组radio: </script>(“input[@type=radio]”).attr(“checked”,’2’);//设置value=2的项目为当前选中项
下拉框select: (“#sel”).attr(“value”,’-sel3’);//设置value=-sel3的项目为当前选中项.。<script type="math/tex" id="MathJax-Element-3">(“#sel”).attr(“value”,’-sel3’);//设置value=-sel3的项目为当前选中项.。
</script>(“11112222“).appendTo(“#sel”)//添加下拉框的option
$(“#sel”).empty();//清空下拉框
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
遍历option和添加、移除option
function changeShipMethod(shipping) {
var len = $("select[@name=ISHIPTYPE] option").length
if (shipping.value != "CA") {
$("select[@name=ISHIPTYPE] option").each(function() {
if ($(this).val() == 111) {
$(this).remove();
}
});
} else {
$("<option value='111'>UPS Ground</option>").appendTo($("select[@name=ISHIPTYPE]"));
}
}
//取得下拉选框的选取值
(#testSelect option:selected’).text();
或<script type="math/tex" id="MathJax-Element-4">(#testSelect option:selected’).text();
或 </script>(“#testSelect”).find(‘option:selected’).text();
或 $(“#testSelect”).val();
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
复选框,推荐如下操作方式
$("#chk2")[0].checked = true;
$("#chk2")[0].checked = false;
本站为非盈利网站,如果您喜欢这篇文章,欢迎支持我们继续运营!
本站主要用于日常笔记的记录和生活日志。本站不保证所有内容信息可靠!(大多数文章属于搬运!)如有版权问题,请联系我立即删除:“abcdsjx@126.com”。
QQ: 1164453243
邮箱: abcdsjx@126.com