在 jquery 中读取以 # 开头的 ID

Read id starting with # in jquery

我正在抓取一个网页,我需要访问的 div 有 id="#abc"。 我正在使用 cheerio 来抓取页面,所以我需要在 JQuery 中进行,但它不起作用:

$('##abc') // undefined

但它适用于纯 javascript:

getElementById("#abc") // works well

尝试使用此 $('#\#abc') 转义带有 id 的任何特殊字符。

Check here

$(function()
{
 var a  = document.getElementById("#abc")
 
 
 var b  = $('#\#abc')
 
 $(b).val("test")
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="#abc" />

你可以试试这个输入(隐藏,文本..)

$("[id='#abc']").val()

正如@Scott Marcus 建议的那样

这适用于所有非表单字段元素:

$("[id='#abc']").html()
$("[id='#abc']").text()

试一试:

$('[id="#abc"]');