網站首頁 編程語言 正文
一、文本輸入框: 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、得到單選框的選中項的值:
$("input[type=radio][name=sex]:checked").val();
2、勾選單選框的項:
$("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");
三、復選框: checkbox
<intput type=”checkbox” name=”sex” value=”0”/>男
<intput type=”checkbox” name=”sex” value=”1”/>女
1、得到所有checked中項的值:
$("input[type=checkbox][name=sex]:checked").each(function(i,n){ //由于復選框一般選中的是多個,所以可以循環輸出
alert($(n).val());
});
2、勾選復選框的項:
$("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、禁用、啟用復選框:
$("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、 獲取選擇項的值:
$("#sel").val();
2、獲取選擇項的文本:
$("#sel option:selected").text();
3、選中第二個項:
$("#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、清空項:
$("#sel").empty();
$("#sel").html('');
6、添加項:
$("#sel").append("<option value='33'>dd</option>");
$("#sel").prepend("<option value=''>請選擇</option>"); //為Select插入一個Option(第一個位置)
7、移除選擇項:
$("#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、 獲取選擇項的值:
$("#selMul").val();//如果多選,返回一個數組val().join(‘,')
2、獲取選擇項的個數:
$(“#selMul option”).length
3、獲取選擇項的文本:
$("#selMul option:selected").each(function(i,n){
$(this).text();
});
4、選中第二個項:
$("#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、清空項:
$("#selMul").empty();
$("#selMul").html('');
7、添加項:
$("#selMul").append("<option value='33'>dd</option>");
$("#selMul").prepend("<option value=''>請選擇</option>"); //為Select插入一個Option(第一個位置)
8、移除選擇項:
$("#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
相關推薦
- 2022-11-21 詳解如何使用Python實現刪除重復文件_python
- 2022-12-22 利用C++求解八數碼問題實例代碼_C 語言
- 2022-11-12 NetCore?配置Swagger的詳細代碼_實用技巧
- 2022-07-10 jQuery表格添加數據并Ajax提交數據
- 2022-03-16 Linux系統中日志詳細介紹_Linux
- 2022-11-09 Python運算符教程之邏輯門詳解_python
- 2022-10-19 Pandas中Series的創建及數據類型轉換_python
- 2022-07-18 BeanUtils工具類
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支