日期:2014-05-16  浏览次数:20484 次

求助,简单正则匹配


<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#selbtn88").click(function(){//选择日历插件时,回到顶部
$("html,body").animate({"scrollTop":"0"},"slow")
})
});
</script>
</head>
<body>
<div style="height:1500px">aaaaa</div>
<div style="height:800px"><span id="selbtn88">123456</span></div>
<div style="height:1500px"></div>
</body>
</html>

#selbrn1_2  后面可能是数值和_ 如何让这类ID点击后 执行回到顶部呢?

谢谢.
------解决方案--------------------
你可以设置id已什么开头
$("span[id^=selbtn]").click(function(){//选择日历插件时,回到顶部
        $("html,body").animate({"scrollTop":"0"},"slow")    
    })

------解决方案--------------------
$(document).click(function(event){
var target = event.target,
$target = $(target);
if(/^selbtn(\d
------解决方案--------------------
_)+/.test($target.attr("id"))) {
$("html,body").animate({"scrollTop":"0"},"slow");
}

// 或者
$("body").click(function(event){
var target = event.target,
$target = $(target);
if(/^selbtn(\d
------解决方案--------------------
_)+/.test($target.attr("id"))) {
$("html,body").animate({"scrollTop":"0"},"slow");
}
});