How to get the parameters of an href attribute of a link from the click event object

前端 未结 4 1215
没有蜡笔的小新
没有蜡笔的小新 2021-02-15 16:37

Is there a simple way to get the parameters at the end of an href attribute of a clicked link using the click event object?

I have some jQuery code that looks like this:

4条回答
  •  猫巷女王i
    2021-02-15 17:11

    You can use the this.href method to read the link attribute:

    $('#pages').delegate("a", "click", function(e) {
       var str = this.href.split('?')[1];
    

    Example:

    str = 'friends.php?term=ma&p=2';
    console.log(str.split('?')[1]); // output: term=ma&p=2
    

提交回复
热议问题