JQuery处理绑定多个button事件

来源:互联网 发布:google 算法面试题 编辑:程序博客网 时间:2024/05/21 18:49

Html片段

<td><button type= "button" id ="tochannel__${topic.topic_name}__${channel.channel_name}" class= "btn btn-link"> ${channel.channel_name} </button ></ td><td><button type= "button" id ="tochannel__${topic.topic_name}__${channel.channel_name}" class= "btn btn-link"> ${channel.channel_name} </button ></ td><td><button type= "button" id ="tochannel__${topic.topic_name}__${channel.channel_name}" class= "btn btn-link"> ${channel.channel_name} </button ></ td>。。。。。。。。

JQuery处理

< script type= "text/javascript" >     $( function (){            $( "button[id^='tochannel_']" ).each( function(){//获取所有的id为tochannel_开头的Button                $( this ).bind("click" , function(){//绑定当前点击的按钮                    var ids = $( this).attr( "id");//获取它的id属性值                    var arr = ids.split("__" );                    var topicName = arr[1];                    var channelName = arr[2];                    window.location.href = "/channel/info?node=${node}&topic=" +topicName+ "&channel="+channelName;                });            });     });</ script >


1 0