我想使用jQuery扫描网站,但ID会不断变化,但我正在搜索的ID有一个永久模式:
app7019261521_the_coinb4678bc2
app7019261521_the_coind42fgr23
app7019261521_the_coing0992gvb
app7019261521_the_coin12e5d0aa
Run Code Online (Sandbox Code Playgroud)
ID始终以app7019261521_the_coin开头
但我的问题是我不知道如何把它放在jQuery选择器中.
$("#app7019261521_the_coin")
Run Code Online (Sandbox Code Playgroud)
似乎没有用
那我怎么能做这个呢?
$("[id^=app7019261521_the_coin]")
Run Code Online (Sandbox Code Playgroud)
应该工作 - 但它比选择真实ID更慢的选择器 - 或分配一个类.此选择器将一次扫描一个页面上的每个元素,没有好的方法可以优化此选择器.虽然你可以构建一个更好的选择器,但是这个#app7019...元素是另一个元素的直接子元素,更容易确定吗?喜欢id='container'?
$("#conainter > [id^=app7019261521_the_coin]"); for instance
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)[attribute^=value] Returns: Array<Element(s)> Matches elements that have the specified attribute and it starts with a certain value.