开发者

set target.id to div id and a number?

The target id below is map_external, but I开发者_开发百科 would like to get map_external(and a number)

I have this:

$('#jqt').bind('pageAnimationStart', function(e, info){
           if (e.target.id == 'map_external') {
                 if (info.direction =='in') {
                    localiser();
                }

and it works, and my target page looks like this:

<div id="map_external">
content....
</div>

but I would like to have a random number aswell, like this:

<div id="map_external<%=asp random number%>">
content....
</div>

so how do i write if (e.target.id == 'map_external') so that it gets map_external and a number(any number)? Thanks!


Try writing it like this:

var newId = e.target.id;
if (newId.indexOf("map_external") > -1) { // will test for the first instance, and find it at 0
        if (info.direction =='in') {
            localiser();
        }
}


Try matching it against a Regex:

if (e.target.id.match(/^map_external\d+/)) {
    // id matches "map_external{number}"
}


Use the attribute contains prefix selector in jQuery http://api.jquery.com/attribute-contains-prefix-selector/

  $('#jqt[id|="map_external"]').bind('pageAnimationStart', function(e, info){

             if (info.direction =='in') {
                localiser();
            }
  });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜