简体   繁体   English

如何将属性选择器与变量一起使用?

[英]How can I use the attribute selector with a variable?

I need to use this form because it can handle spaces in my element ID. 我需要使用此表单,因为它可以处理元素ID中的空格。

$("div[id='content Module']").whatever();

However I need 'content Module' replaced with a variable? 但是我需要将“内容模块”替换为变量吗?

I tried 我试过了

$("div[id=" + my_var + "']").whatever();

but this did not work 但这没有用

You're missing a ' 您缺少“

$("div[id=" + my_var + "']").whatever();

Should be 应该

$("div[id='" + my_var + "']").whatever();

try this $("div[id='" + my_var + "']").whatever(); 试试这个$("div[id='" + my_var + "']").whatever(); you forgot the open Apostrof 你忘记了开放的使徒

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何 Append Id 属性选择器或将 Id 存储在 Jquery 变量中并将该变量用作选择器? - How can I Append the Id attribute Selector or Store the Id in Jquery variable and use that variable as selector? 我可以在 queryselector() 中为 CONTAINS 使用属性选择器吗? - Can I use an attribute selector for CONTAINS in queryselector()? 如何在属性中使用 javascript 变量? - How can i use a javascript variable into an attribute? 如何在Jquery Selector中使用c#ViewBag变量? - How can I use c# ViewBag variable in Jquery Selector? 我可以使用角度组件选择器作为该组件的属性吗? - Can I use an angular component selector as an attribute for that component? 如何使用变量在查询中的数据属性上设置值 - How can I use a variable to set the value on a data attribute in query 如何获得选择器计数并传递给以后可以使用的变量? - How to I get a count of a selector and pass into a variable I can use later? 如何将jQuery选择器:not()选择器与getElementsByClassName一起使用 - How can I use getElementsByClassName with jQuery selector :not() selector 我如何在这里与选择器一起使用 - How can I use this here with selector jQuery文档更改:我可以使用变量作为选择器吗? - Jquery document on change: can I use variable as selector?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM