在数据标题中使用带有某种正则表达式比较的jquery查找元素? [英] Find an element using jquery with a kind of regex comparison in the data-title?
本文介绍了在数据标题中使用带有某种正则表达式比较的jquery查找元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想选择一个类为textbox
的div,并且还要具有一个以变量dt
中的字符串开头的数据标题.
像这样:
I want to select a div with class textbox
and also has a data-title that starts with the string in the variable dt
.
Something like this:
var $theboxes = $(".textbox[data-title^="+dt+"]");
我已经尝试过了,但是这会导致jquery中的错误.什么是正确的方法?
I've tried this but it causes an error in jquery. What's the right way to do this?
推荐答案
我认为您实际上需要引用属性值.
尝试这样的事情:
I think you actually need to quote the attribute value.
Try something like this:
var $theboxes = $(".textbox[data-title^='"+dt+"']");
这篇关于在数据标题中使用带有某种正则表达式比较的jquery查找元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文