返回目录

表单  :input :text :password :radio :checkbox :submit :image :reset :button :file :hidden :selected :checked 
基本   :first :last :not :even :odd :eq :gt :lt :header :animated  
内容   :contains :empty :has :parent  
可见性  :hidden :visible 

  1. li:has(a) //包含有a标签的li元素
  1. $(\'input[name*="id"]:not(:checked)\').each(function () {
  2. unselectIds.push($(this).val());
  3. });
  4. //所有未选中的checkbox框

jQuey [] 内是dom属性, 用=等号链接相应的属性值

  1. $(\'input[name*="id"]\').attr(\'checked\',o.checked);//选择input name元素中包含字符id,并使其置为选中状态
  1. //jquery-1.8.2.js 中括号属性选取器
  2. $("[opentype][class=easysite-mt10]").css("border","1px solid #ff0000")
  3. //读作:选中同时有属性(attr) opentype和class=easysite-mt10的DOM节点

 

参考

返回目录

  1. 1. jQuery对象.addClass("DrugsActive"), 为节点增加class="xxx" 属性
  2. 1.1. jQuery对象.removeClass("DrugsActive")
  3. 2. jQuery对象.css("width", "20%"); //直接为jquery对象修改css样式
  1. $("#tblPart1>tbody>tr[id^=\'q\']:odd").addClass("tr-dark");

 

  1. switch ($("#divSearchBy" + divId).css("display")) {
  2. case "none":
  3. $("#divSearchBy" + divId).show();
  4. $("#divSearchBy" + divId).css("display", "block");

jQuery show()方法的逆方法 .hide()

  1. var vid = "#" + $(this).attr("id");
  1. .removeAttr("readonly")
  1. $("#txtUserName,#txtContact,#txtTelephone,#txtEmail").attr("readonly", "readonly");

 

  1. $("input[name=\'" + roleRecords[i].MenuID + "\']").attr("checked", true);
  1. var allCheckbox = $("[name$=\'cbR\']");

表示name它的字面值以cbR结尾,其它 label[name*=\’industry\’] 表示包含

  1. $("input[id$=cbxSelect]", document.getElementById("ctl00_ContentPlaceHolder1_grvScale"))

第2个参数是dom结构

例2

  1. $("tr[id^=\'q\']", "#tblPart1").each(function () {
  2. if ($("input:checkbox:checked", this).length == 0) {
  3. hasNoAnswer = true;
  4. noAnswerTrId.push($(this).attr("id"));
  5. }
  6. });

读作: 在id=tblPart1的节点中,查找所有id以q开头的dom元素, 之后使用 $(“input:checkbox:checked”, this) 在它内部查找checkbox元素,并判断是否被选中(做必须判断)

  1. var value = $(\'.modal-body\').find("input[type=\'text\']").val();//在class="modal-body"的DOM节点内查找

 

1.

  1. $("input[type=\'checkbox\'][name=\'" + item.name + "\']:checked")

2.选择type=checkbox 同时属性disabled!=true的

  1. $("input[type=\'checkbox\'][disabled!=disabled]").attr("checked",true);
  1. $("#txtUserName,#txtContact,#txtTelephone,#txtEmail").removeAttr("readonly");
  1. $("#outRegistList tr").find("td:last").each(function(index,item){
  2. if (item.innerText == "") {
  3. alert("还有外出未返回不能新增!");
  4. return;
  5. }
  6. })

 

Table复选框全选及不为空之jquery 实例

  1. $(function () {
  2. $("#allCheck").bind("click", function () {
  3. $("[name = $chkItem]:checkbox").attr("checked", $(this).attr("checked"));
  4. });
  5. })
  6. function beforExport() {
  7. var flag;
  8. $("[name = $chkItem]:checkbox").each(function () {
  9. if ($(this).attr("checked") == true) {
  10. flag = true;
  11. return flag;
  12. }
  13. });
  14. if (!flag) {
  15. alert("至少勾选1项导出凭证");
  16. return false;
  17. }
  18. }
  1. $("body").delegate("#tb_2 tr", "click", function () {
  2. $(this).addClass(\'tr_color\').siblings("tr").removeClass("tr_color");
  3. });
  1. $(".tbl-list>tbody>tr").hover(
  2. function () { $(this).addClass("tr-hover"); },
  3. function () { $(this).removeClass("tr-hover"); }
  4. );
  1. $("tr", "#lstBody").hover(
  2. function () { $(this).addClass(\'tr-hover\'); },
  3. function () { $(this).removeClass(\'tr-hover\');
  4. });

 

  1. 1 function GetSelectHS(){
  2. 2 var select = $(\'<div></div>\');
  3. 3 $.each(nurser, function (i,item) {
  4. 4 $("<option></option>")
  5. 5 .val(item.id)
  6. 6 .text(item.Name)
  7. 7 .appendTo(select);
  8. 8 });
  9. 9 return $(select).html();
  10. 10 }

第3行nurser是对象集合, i是索引

  1. var YS = {
  2. 2: \'2.嗜睡\',
  3. 3: \'3.意识模糊\'
  4. }
  5. function GetSelectYS(){
  6. var select = $(\'<div></div>\');
  7. $.each(YS, function (i, item) {
  8. $("<option></option>")
  9. .val(i)
  10. .text(item)
  11. .appendTo(select);
  12. });
  13. return $(select).html();
  14. }
  1. var allShowTds = $("td[name=\'row_"+dataIndex+"\']");
  2. allShowTds.each(function(){
  3. //$(this)取得当前jquery对象
  4. });

 参考1  参考2

  1. //$this是<a>对象
  2. $this.parents(\'tr\').next().length == 0
  1. $("#search").click(function () {
  2. $("#myTabs").find("a").each(function () {
  3. if ($(this).parent().attr("class") === "active") {
  4. if ($(this).attr("href") === "#table1") {
  5. createPuzzleFeeTableFromPortal();
  6. }
  7. else {
  8. createPuzzleFeeTableFromPortalTab2();
  9. }
  10. }
  11. })
  12. });

为boostrap中Tab页绑定处理事件

  1. $(\'#myTabs a\').click(function (e) {
  2. e.preventDefault();
  3. if ($(this).attr("href") === "#table1" || $(this).parent().attr("class") === "active") {
  4. $("#tab1FeeType").show();
  5. $("#tab1FeeType").css("display", "block");
  6. $("#tab2FeeType").hide();
  7. $("#tab2FeeType").css("display", "none");
  8. }
  9. else {
  10. $("#tab2FeeType").show();
  11. $("#tab2FeeType").css("display", "block");
  12. $("#tab1FeeType").hide();
  13. $("#tab1FeeType").css("display", "none");
  14. }
  15. })

1. $(“p,div,span.menuitem”)  相当于or的作用,表示同时选择p标签,div标签,和拥有menuitem样式的span标签元素

2.在指定的某个范围的选择器,即相对选择器

  1. <table id="table1">
  2. <tr><td>dsds</td><td>dsfdef</td></tr>
  3. <tr><td>dsds</td><td>dsfdef</td></tr>
  4. <tr><td>dsds</td><td>dsfdef</td></tr>
  5. <tr><td>dsds</td><td>dsfdef</td></tr>
  6. <tr><td>dsds</td><td>dsfdef</td></tr>
  7. </table>
  8. <script type="text/javascript">
  9. $(function () {
  10. $("#table1 tr").click(function () {
  11. $("td", $(this)).css("background", "red"); //相对选择器,选择出的td是以当前的tr为相对的元素。选择的td元素是当前的tr元素下的所有td元素,没有涉及到其他行的td元素
  12. });
  13. });
  14. </script>
  1. $(document).ready(function () {
  2. $(".nei-nav li a").bind("click", function () {
  3. $(".nei-nav li").each(function () {
  4. $(this).removeAttr("class");
  5. //$(this).attr("class", "");
  6. })
  7. setActive();
  8. })
  9. setActive();
  10. });
  11. function setActive() {
  12. var curType = $("#curType").val();
  13. $("#" + curType).attr("class", "active");
  14. }

 

  1. var topImgUrl = [
  2. "http://www.ciicsh.com/eportal/uiFramework/commonResource/image/2020082615213661087.jpg",
  3. "http://www.ciicsh.com/eportal/uiFramework/commonResource/image/2020082615215522690.jpg",
  4. "http://www.ciicsh.com/eportal/uiFramework/commonResource/image/2020082615220813883.jpg"
  5. ]
  6. $(document).ready(function () {
  7. $(".newsItem .thumbnail").each(function (index, item) {//范围选择器,在class=newsItem下查找class=thumbnail DOM
  8. // if(index== 1){
  9. // //$(this).attr("class", "thumbnail even");
  10. // $(this).addClass("even")
  11. // }
  12. var data = $("p.hidden-data", $(this)).text();//范围选择器例子
  13. var gzpp = data.split("|");
  14. $(".gzpp-local", $(this)).text(gzpp[0]);
  15. $(".gzpp-position", $(this)).text(gzpp[1]);
  16. $(".gzpp-company", $(this)).text(gzpp[2]);
  17. $(".gzpp-other", $(this)).text(gzpp[3]);
  18. })
  19. $(".caption-pic").each(function(index,item) {
  20. $(this).css("background-image", "url(" + topImgUrl[index] + ")");
  21. $(this).css("background-size", "cover");
  22. //debugger
  23. //$(".top-img", $(this)).css("background-image", "url(" + topImgUrl[index] + ")");
  24. //$(item).css("background-image", "url(" + topImgUrl[index] + ")");
  25. //$(this).css("background","rgba(0,0,0,0.8)");
  26. //$(this).css("background", "#fff url(" + topImgUrl[index] + ") no-repeat center center;");
  27. })
  28. });
  1. $(".zg_rc1 :checkbox") //查找.zg_rc1这个类下的所有复选框,中间有个空格
  1. $(.test :hidden) // 选择class为test元素当中的隐藏子元素

区别

  1. $(.test:hidden) // 选择隐藏的class为test的元素

 

End

 

版权声明:本文为zhuji原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/zhuji/p/6701880.html