开发者

jquery.address: $.address.change() runs twice when using $.address.queryString()

开发者 https://www.devze.com 2023-03-19 15:10 出处:网络
$.address.change() runs twice when using $.address.queryString() if have a url of: www.example.com and i run the following code:

$.address.change() runs twice when using $.address.queryString()

if have a url of:

www.example.com

and i run the following code:

开发者_C百科
$.address.change(function(event)
{    
    if(event.parameters['user_id'])
    {
        alert(event.parameters['user_id'])
    }       
});
$.address.queryString('user_id=902715614&user_name=James');

Live example

it alerts the user_id twice

however, shouldn't it only alert once?


It's probably alerting when the page loads (address changed...right?), and then again when YOU change the address.


Without more context it's hard to tell if this makes sense... but should you be calling your function after the DOM is ready like this:

$(document).ready(function () {
  $.address.queryString('user_id=902715614&user_name=James');
});
0

精彩评论

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