網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
一、文本輸入框: text
<input type=”text” value=”99.com” size=12 id=”input1” />
1、獲取文本值:
$("#input1").val();
2、選中文本:
$("#input1").select();
3、禁用、啟用文本框
$("#input1”].attr("disabled",true);
4、只讀、取消只讀:
$("#input1”].attr("readonly",true);
二、單選框: radio
<intput type=”radio” name=”sex” value=”0”/>男
<intput type=”radio” name=”sex” value=”1”/>女
1、得到單選框的選中項(xiàng)的值:
$("input[type=radio][name=sex]:checked").val();
2、勾選單選框的項(xiàng):
$("input:radio][name=sex][value=0]).prop("checked",true);
--或者
$("input:radio][name=sex”]).val([”0”]);
3、判斷是否勾選:
$("input:radio][name=sex][value=0]).prop("checked")==true;
4、禁用、啟用單選框:
$("input:radio][name=sex].prop("disabled",true);
--或
$("input:radio][name=sex].removeAttr("disabled");
三、復(fù)選框: checkbox
<intput type=”checkbox” name=”sex” value=”0”/>男
<intput type=”checkbox” name=”sex” value=”1”/>女
1、得到所有checked中項(xiàng)的值:
$("input[type=checkbox][name=sex]:checked").each(function(i,n){ //由于復(fù)選框一般選中的是多個(gè),所以可以循環(huán)輸出
alert($(n).val());
});
2、勾選復(fù)選框的項(xiàng):
$("input:checkbox][name=sex][value=0]).prop("checked",true);
--或者
$("input:checkbox][name=sex”]).val([”0”]);
3、判斷是否勾選:
$("input:radio][name=sex][value=0]).prop("checked")==true;
4、禁用、啟用復(fù)選框:
$("input:checkbox][name=sex].prop("disabled",true);
--或
$("input:checkbox][name=sex].removeAttr("disabled");
5、全選、全不選
$("input:checkbox][name=sex].prop("checked",true);
--或
$("input:checkbox][name=sex].removeAttr("checked");
6、反選
$("input[type=checkbox][name=sex]").each(function(i,n){
$(this).attr('checked',!$(this).attr('checked')==true);
});
四、下拉框 select
<select name="select" id="sel">
<option value="00">a </option>
<option value="11">b </option>
<option value="22">c </option>
</select>
1、 獲取選擇項(xiàng)的值:
$("#sel").val();
2、獲取選擇項(xiàng)的文本:
$("#sel option:selected").text();
3、選中第二個(gè)項(xiàng):
$("#sel").val("11");
$("#sel").val(["11"]);
$("#sel").val("b");
$("#sel").val(["bb"]);
$("#sel option[value="11"]").attr("selected",true);
$("#sel option:contains('b')").attr("selected",true);
4、禁用、啟用下拉框:
$("#sel"].prop("disabled",true);
--或
$("#sel").removeAttr("disabled");
5、清空項(xiàng):
$("#sel").empty();
$("#sel").html('');
6、添加項(xiàng):
$("#sel").append("<option value='33'>dd</option>");
$("#sel").prepend("<option value=''>請(qǐng)選擇</option>"); //為Select插入一個(gè)Option(第一個(gè)位置)
7、移除選擇項(xiàng):
$("#sel option:selected").remove();
五、多選下拉框 select-multiple
<select name="selectMul" id="selMul" size=4 multiple=”multiple”>//size列表框的高度
<option value="00">a </option>
<option value="11">b </option>
<option value="22">c </option>
</select>
1、 獲取選擇項(xiàng)的值:
$("#selMul").val();//如果多選,返回一個(gè)數(shù)組val().join(‘,')
2、獲取選擇項(xiàng)的個(gè)數(shù):
$(“#selMul option”).length
3、獲取選擇項(xiàng)的文本:
$("#selMul option:selected").each(function(i,n){
$(this).text();
});
4、選中第二個(gè)項(xiàng):
$("#selMul ").val("11");
$("#selMul ").val(["11",”22”]);
$("#selMul ").val("b");
$("#selMul ").val([“aa”,"bb"]);
$("#selMul option[value="11"]").attr("selected",true);
$("#selMul option:contains('b')").attr("selected",true);
5、禁用、啟用下拉框:
$("#selMul"].prop("disabled",true);
--或
$("#selMul").removeAttr("disabled");
6、清空項(xiàng):
$("#selMul").empty();
$("#selMul").html('');
7、添加項(xiàng):
$("#selMul").append("<option value='33'>dd</option>");
$("#selMul").prepend("<option value=''>請(qǐng)選擇</option>"); //為Select插入一個(gè)Option(第一個(gè)位置)
8、移除選擇項(xiàng):
$("#selMul option:selected").remove();
9、全選、全不選
$("#selMul option).attr("selected",true);
--或
$("("#selMul option).removeAttr("selected");
10、反選
$("#selMul option).each(function(i,n){
$(this).attr(‘selected',!$(this).attr(‘selected')==true);
});
原文鏈接:https://www.cnblogs.com/springsnow/p/9461753.html
相關(guān)推薦
- 2022-06-29 docker環(huán)境搭建mgr集群的問(wèn)題及原理_docker
- 2022-07-10 laravel 中 distinct() 的使用方法與去重
- 2022-08-11 關(guān)于pyqtSignal的基本使用_python
- 2022-10-05 Numpy中Meshgrid函數(shù)基本用法及2種應(yīng)用場(chǎng)景_python
- 2022-07-17 Go語(yǔ)言入門exec的基本使用示例_Golang
- 2022-06-22 Docker中?container?和?image?的命名_docker
- 2022-12-07 C語(yǔ)言內(nèi)存分布與heap空間分別詳細(xì)講解_C 語(yǔ)言
- 2022-04-09 Python中變量的作用域詳解_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支