是否可以使用jquery选择以'starting'开头的所有div id +'some random number'+'ending'
示例
requirejs.config({
paths: {
"react-addons-create-fragment": "react-addon-modules",
"react-addons-transition-group": "react-addon-modules",
"react-addons-update": "react-addon-modules"
}
});
是否可以通过一个查询选择所有内容? 在某种意义上$('#+'开头“+”随机数选择器“+”结尾“')......?
答案 0 :(得分:1)
是的,有attribute starts with selector和attribute ends with selector
脚本如下所示。
$('div[id^="starting"][id$="ending"]')
下面是一个视觉样本
$('div[id^="starting"][id$="ending"]').css('background-color','yellow');
div {
width: 100px;
height: 100px;
border: 2px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="startingending"></div> <!-- select this -->
<div id="starting789ending"></div> <!-- select this -->
<div id="starting789"></div>
<div id="starting789ending"></div> <!-- select this -->
<div id="789ending"></div>
<div id="starting789ending"></div> <!-- select this -->