[英]How can I use a wild card with .html in JQuery?
How can I use a wild card to update divs? 如何使用通配符更新div?
I want to change two sets of divs (one has additional information at the end). 我想更改两组div(一组末尾有其他信息)。
I am using an each loop and do not want to do any sort of searching or find. 我正在使用每个循环,并且不想进行任何形式的搜索或查找。 I know the beginning is the same for all the divs.
我知道所有div的开始都是一样的。
Want to change this one as well: '#div\\\\\\:'+month+'\\\\\\:'+day+'\\\\\\:'+time+'\\\\\\:'+additionalInfo;
也要更改此设置:
'#div\\\\\\:'+month+'\\\\\\:'+day+'\\\\\\:'+time+'\\\\\\:'+additionalInfo;
First Div Type 第一股类型
div:2:25:1530
Second Div Type 第二分部类型
div:2:25:1530:3065
Code: 码:
var div = '#div\\\:'+month+'\\\:'+day+'\\\:'+time;
$(div).html('<a class="btn btn-block btn-custom">TEST</a>');
I use the triple slash because the double was not working for some reason. 我使用三斜杠,因为双斜杠由于某种原因无法正常工作。 But worked when I added the third, not sure why.
但是当我添加第三个时就可以了,不知道为什么。
You can use one of the attribute selectors to target multiple divs with a similar id or class name - there really isn't one for regexp 您可以使用属性选择器之一将具有相同ID或类名称的多个div定位为目标-regexp确实没有一个
For example, say you have a div ID of <div id="div:01:01:2015:info1"></div>
, you can target it with this selector: 例如,假设您的div ID为
<div id="div:01:01:2015:info1"></div>
,则可以使用以下选择器定位它:
Starts with selector ^=
以选择器
^=
开头
// target all divs for January (assuming mm:dd:yyyy)
$('[id^="div\\:01"]')
Contains selector *=
包含选择器
*=
// target all divs for 2015
$('[id*="2015"]')
etc 等等
Update: Use two backslashes \\\\
to escape meta characters 更新:使用两个反斜杠
\\\\
转义元字符
!"#$%&'()*+,./:;<=>?@[\]^`{|}~
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.