jquery-ui-tabs. passing a querystring

为君一笑 提交于 2019-12-23 10:19:12

问题


How could I pass a query string (?id=avalue) with each of the below links associated to the below tabs. I am attempting to open external content within the tabs (that it's working fine) but I have failed to pass a parameter with the urls. The value for the parameter would be the same for each link.

My functioning code:

<script type="text/javascript">

        $(function() {
            $("#tabs").tabs({spinner:'<b>Retrieving Data...</b>'}); 

        });

 </script>


<div id="tabs">
            <ul>
           <li><a href="table.aspx"><span>Introduction</span></a></li>
                <li><a href="RequestActionUpdate.aspx"><span>Update</span></a></li>
                <li><a href="tabstesttarget.aspx"><span>Target</span></a></li>
                <li><a href="table.aspx" ><span>View History</span></a></li>
            </ul>

        </div>

Any help you can offer me will be much appreciated.

Thanks in advance


回答1:


You can use the ajaxOptions option. The tabs widget will pass these options onto jQuery.ajax().

The following code uses the data option of the jQuery.ajax() function to pass the result of the getId function (a Unix-style time code in this example) to the server when a tab is selected.
The request url will look something like RequestActionUpdate.aspx?id=1255015611701:

function getId() {
  return (new Date()).getTime();
}

$("#tabs").tabs({
  spinner:'<b>Retrieving Data...</b>',
  ajaxOptions: { data: { id: getId } }
});



回答2:


You can hardcode the parameter to each link:

<li><a href="RequestActionUpdate.aspx?id=avalue"><span>Update</span></a></li>

This should work just fine. What exactly is not working for you? Or you have something else in mind?




回答3:


From the searching that I've done, the best way to approach this without having to do something ugly like:

window.location = href + '?id=avalue'

would be to update the anchor hrefs on the page load. Grab whatever ID/value you need, and just append it;

$(document).ready(function(){
    value = "?id=foobar"
    $("#tabs ul li a").attr('href', ($(this).attr('href') + value) );
});

Not the most elegant solution, but it does work.




回答4:


What happens if you add an event observer on all the links?

$("#tabs ul li a").click(
    function(){
       $(this).attr('href', $(this).attr('href') + $('#someHiddenInput').val());
     }
);


来源:https://stackoverflow.com/questions/1538189/jquery-ui-tabs-passing-a-querystring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!