87,910
社区成员
发帖
与我相关
我的任务
分享
<div class="menu">
<ul id="a1b1">...</ul>
...
<ul id="a11b23">...</ul>
...
<ul id="a35b12">...</ul>
...
<ul id="a68b98">...</ul>
<ul id="a68b99">...</ul>
...
<ul id="a100b100">...</ul>/* 数字大于99,不需要修改 */
...
</div>
jQuery(document).ready(function(){
var menuArray = $('.menu').children('ul');
var id = $('.menu').children('ul').attr('id');
for (myul in menuArray) {
var matches = id.match(/^a\d{1,2}b\d{1,2}$/);
if (matches[1]) {
$(myul).css({...});
}
}
});
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(function(){
$(".menu").children("ul").each(
function(){
if($(this).attr("id").match(/^a\d{1,2}b\d{1,2}$/))
{
$(this).css("color","red");
}
}
);
});
</script>
</head>
<body>
<div class="menu">
<ul id="a1b1">1-1</ul>
<ul id="a11b23">11-23</ul>
<ul id="a35b12">35-12</ul>
<ul id="a68b98">68-98</ul>
<ul id="a68b99">68-99</ul>
<ul id="a100b100">100-100</ul>
</div>
</body>
</html>
var re = new RegExp("^a\\d{1,2}b\\d{1,2}$","");
$('.menu').find('ul').each(
function(){
if(re.test($(this).attr('id'))){
$(this).html("true");
}
}
)
<div class="menu">
<ul id="a1b1">1-1</ul>
<ul id="a11b23">11-23</ul>
<ul id="a35b12">35-12</ul>
<ul id="a68b98">68-98</ul>
<ul id="a68b99">68-99</ul>
<ul id="a100b100">100-100</ul>
</div>