本文翻译自:jQuery selector regular expressions

I am after documentation on using wildcard or regular expressions (not sure on the exact terminology) with a jQuery selector. 我正在阅读使用jQuery选择器使用通配符或正则表达式(不确定的确切术语)的文档。

I have looked for this myself but have been unable to find information on the syntax and how to use it. 我自己一直在寻找,但一直无法找到有关语法和如何使用它的信息。 Does anyone know where the documentation for the syntax is? 有谁知道语法的文档在哪里?

EDIT: The attribute filters allow you to select based on patterns of an attribute value. 编辑:属性过滤器允许您根据属性值的模式进行选择。


#1楼

参考:https://stackoom.com/question/nUb/jQuery选择器正则表达式


#2楼

$("input[name='option[colour]'] :checked ")

#3楼

James Padolsey created a wonderful filter that allows regex to be used for selection. James Padolsey创建了一个精彩的过滤器 ,允许正则表达式用于选择。

Say you have the following div : 假设你有以下div

<div class="asdf">

Padolsey's :regex filter can select it like so: Padolsey :regex过滤器可以选择它:

$("div:regex(class, .*sd.*)")

Also, check the official documentation on selectors . 另外,查看选择器的官方文档 。


#4楼

You can use the filter function to apply more complicated regex matching. 您可以使用filter函数来应用更复杂的正则表达式匹配。

Here's an example which would just match the first three divs: 这是一个与前三个div匹配的示例:

 $('div') .filter(function() { return this.id.match(/abc+d/); }) .html("Matched!"); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="abcd">Not matched</div> <div id="abccd">Not matched</div> <div id="abcccd">Not matched</div> <div id="abd">Not matched</div> 

#5楼

If your use of regular expression is limited to test if an attribut start with a certain string, you can use the ^ jquery selector 如果使用正则表达式仅限于测试attribut是否以某个字符串开头,则可以使用^ jquery选择器

For example if your want to only select div with id starting with "abc", you can use $("div[id^='abc']") 例如,如果您只想选择ID为“abc $("div[id^='abc']") ,则可以使用$("div[id^='abc']")

A lot of very useful selectors to avoid use of regex can be find here : http://api.jquery.com/category/selectors/attribute-selectors/ 可以在这里找到许多非常有用的选择器以避免使用正则表达式: http : //api.jquery.com/category/selectors/attribute-selectors/


#6楼

These can be helpful. 这些可能会有所帮助。

If you're finding by Contains then it'll be like this 如果你是通过Contains找到它那么就是这样的

    $("input[id*='DiscountType']").each(function (i, el) {//It'll be an array of elements});

If you're finding by Starts With then it'll be like this 如果您通过Starts With找到它,那么它就像这样

    $("input[id^='DiscountType']").each(function (i, el) {//It'll be an array of elements});

If you're finding by Ends With then it'll be like this 如果你是通过Ends With找到它那么就像这样

     $("input[id$='DiscountType']").each(function (i, el) {//It'll be an array of elements});

If you want to select elements which id is not a given string 如果要选择id不是给定字符串的元素

    $("input[id!='DiscountType']").each(function (i, el) {//It'll be an array of elements});

If you want to select elements which id contains a given word, delimited by spaces 如果要选择id包含给定单词的元素,则用空格分隔

     $("input[id~='DiscountType']").each(function (i, el) {//It'll be an array of elements});

If you want to select elements which id is equal to a given string or starting with that string followed by a hyphen 如果要选择id等于给定字符串或以该字符串后跟连字符开头的元素

     $("input[id|='DiscountType']").each(function (i, el) {//It'll be an array of elements});

jQuery选择器正则表达式相关推荐

  1. Jquery 选择器大全 【转载】

    选择器是jQuery最基础的东西,本文中列举的选择器基本上囊括了所有的jQuery选择器,也许各位通过这篇文章能够加深对jQuery选择器的理解,它们本身用法就非常简单,我更希望的是它能够提升个人编写 ...

  2. jQuery选择器全集详解

    选择器是jQuery最基础的东西,本文中列举的选择器基本上囊括了所有的jQuery选择器,也许各位通过这篇文章能够加深对jQuery选择器 的理解,它们本身用法就非常简单,我更希望的是它能够提升个人编 ...

  3. jQuery选择器大全(48个代码片段+21幅图演示)

    转载收藏于:http://www.cnblogs.com/keepfool/archive/2012/06/02/2532203.html 选择器是jQuery最基础的东西,本文中列举的选择器基本上囊 ...

  4. jQuery选择器代码详解(一)——Sizzle方法

    对jQuery的Sizzle各方法做了深入分析(同时也参考了一些网上资料)后,将结果分享给大家.我将采用连载的方式,对Sizzle使用的一些方法详细解释一下,每篇文章介绍一个方法. 若需要转载,请写明 ...

  5. 【jquery】jquery选择器

    知识点 1.jquery选择器的作用是选择jquery页面中的html元素. 2.常用的选择器有:基本选择器.层级选择器.过滤选择器.属性选择器. 基本选择器 1. id 选择器 代码实现: elem ...

  6. JQuery——选择器分类

    JQuery选择器 1    什么是JQuery选择器 快速高效的找到指定节点,支持css语法设置页面 2   JQuery选择器分类 2.1   基本选择器 CSS选择器 层级选择器 表单域选择器 ...

  7. jQuery选择器实现隔行变色和使用javaScript实现隔行变色

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!--什么是选择器? jQuery选择器继承了 ...

  8. jQuery 学习笔记一(认识jQuery jQuery选择器 jQuery中的DOM操作)

    第一章 认识jQuery jQuery代码风格 $(document).ready(function(){ //... }); 简化 $(function(){ //... }); jQuery对象转 ...

  9. jQuery选择器回顾,IE8还需要你发光发热

    2019独角兽企业重金招聘Python工程师标准>>> 今天又把jQuery的选择器看了一下,感觉有好几个一直都没有用过.现在有这么多模板双向绑定之类先进思想的前端框架,也不知道jq ...

最新文章

  1. 什么是码元计算机通信
  2. 改进型 clock 页面置换算法实现_ID生成算法雪花算法介绍及实现
  3. Nature Methods:微生物来源分析包SourceTracker——结果解读和使用教程
  4. Fedora 31 Beta 准时发布,带来许多激动人心的更新
  5. BloomFilter–大规模数据处理利器(转)
  6. php统计凌晨6点,凌晨是哪一段时间,0:00-6:00(午夜到天亮前)
  7. Linux 共享内存详解一
  8. [hihoCoder] 第五十周: 欧拉路·二
  9. Linux系统调用getuid的简单分析
  10. SpringActionscript3 片断
  11. 计算机中文无敌版,与电脑下象棋无敌版
  12. 在虚拟机、Mac 电脑和旧电脑上绕过 TPM 安装 Windows 11 的方法总结(提供通用无 TPM 检测镜像下载)
  13. 5G常见缩略语大全收藏
  14. python中fn是什么意思_Python fn
  15. 从基本组件到结构创新,67页论文解读深度卷积神经网络架构
  16. oracle导入报错ora01652,Oracle ORA-01652错误
  17. 2022年 HSC-1th中CRYPTO的RSA
  18. aspx页面打开html文件,aspx文件如何打开
  19. 【最强大脑vs人工智能】脑王水哥王昱珩惜败人工智能, 这不可能. - 图像识别到底是什么鬼
  20. 关于Linux的用户密码(sha512是否有办法解密)

热门文章

  1. 数学建模-Topsis综合评价(评价模型)
  2. python内置函数调整_python - 内置函数
  3. Jmeter下的bugfree的登录、新建bug、解决bug
  4. 详解USACO这个神奇的OJ
  5. C++ 变量名命名规则
  6. 我如何用Unity3D实现一个Galgame框架(一)
  7. 收购Beats凸显苹果潮流可穿戴战略
  8. linux 下执行命令返回inaccessible or not found错误问题
  9. DHC插件的下载与安装
  10. 异步实现:回调回调和消息队列