三、定制的选择器(Custom Selectors)

[1] :blank 返回:Array<Element>
说明:匹配所有空值的表单元素。没有任何值或都空白符(whitespace)都被认为是空值。
它是由 jQuery.trim(value).length == 0 来判断的。

Js代码
$("input:blank").css("background-color", "#bbbbff");

[2] :filled 返回:Array<Element>
说明:匹配所有不为空的表单元素。任何值都可以认为是已输入的,但只有空白符的值除外。
它是由 jQuery.trim(value).length > 0 来判断的。

Js代码
$("input:filled").css("background-color", "#bbbbff");

[3] :unchecked 返回:Array<Element>
说明:匹配所有未选择的表单元素。反向操作为 :checked

Js代码
function countUnchecked() {
var n = $("input:unchecked").length;
$("div").text(n + (n == 1 ? " is" : " are") + " unchecked!");
}
countUnchecked();
$(":checkbox").click(countUnchecked);

 

四、实用工具(Utilities)

jQuery.validator.format( template, [argument], [argumentN...] ) 返回:String
参数 template 类型:String 要格式化的字符串
参数 argument (Optional) 类型:String, Array<String> 用字符串或字符串数组(对应索引的元素)填充第一个占位符
参数 argumentN... (Optional) 类型:String 填充第二个或之后的占位符。
说明:用参数来填充{n}占位符。除template外的一个或多个参数都可以用来填充相应的占位符。

Js代码
$(document).ready(function(){
$("button").click(function () {
var str = "Hello {0}, this is {1}";
alert("'" + str + "'");
str = jQuery.validator.format(str, "World", "Bob");
//str = $.validator.format(str, ["koala","oo"]);
alert("'" + str + "'");
});
});

jQuery相关内容:

相关文章:

  • 2021-11-03
  • 2021-06-28
  • 2021-10-21
  • 2021-10-14
  • 2021-12-04
  • 2021-12-22
  • 2022-12-23
  • 2021-06-23
猜你喜欢
  • 2021-11-16
  • 2022-03-10
  • 2021-06-23
  • 2021-10-25
  • 2022-01-11
  • 2021-07-04
  • 2022-02-01
相关资源
相似解决方案