getting url values in jquery mobile?

2019-05-26 03:57发布

问题:

i am trying to get the value attached in the url using jquery mobile.

http://localhost/testing/nothing.html#details?id=0&color=blue

I want to get the id = 0 and color = blue using jquery mobile when i go to the "details" page:

$('#details').live('pagecreate',function(event) {

});

Thanks.

回答1:

Please check this link

Write the fucnction like shown below

$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;

}

To get a particular value just call the function and pass the name of the parameter

    $.urlParam('id');