简体   繁体   English

如果占位符的属性值包含斜杠和空格,如何使用 querySelectorAll 按属性值计算 select

[英]How to select by attribute value using querySelectorAll if attribute value of placeholder contains slash and space

Let me explain example让我解释一下例子

<input placeholder='MM / YY'>

My query is document.querySelectorAll('[placeholder=MM \/ YY]') .我的查询是document.querySelectorAll('[placeholder=MM \/ YY]')

But it throws error Failed to execute 'querySelectorAll' on 'Document': '[placeholder=MM / YY]' is not a valid selector.但它抛出错误Failed to execute 'querySelectorAll' on 'Document': '[placeholder=MM / YY]' is not a valid selector.

Add quotes around the attribute value:在属性值周围添加引号:

 console.log( document.querySelector('[placeholder="MM \/ YY"]') );
 <input placeholder='MM / YY'>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM