简体   繁体   English

使用 jQuery 选项卡更改变量

[英]Changing variable with jQuery tabs

I have a Google style instant search script written in jQuery which pulls results from a PHP script.我有一个用 jQuery 编写的 Google 风格的即时搜索脚本,它从 PHP 脚本中提取结果。 I want to make a script so I can change the destination of the file by clicking a certain link.我想制作一个脚本,这样我就可以通过单击某个链接来更改文件的目的地。 How can I make it so when a certain link is clicked it changes the selected.tab variable to the name of the search type.我怎样才能做到这一点,当单击某个链接时,它会将 selected.tab 变量更改为搜索类型的名称。 How can I do this?我怎样才能做到这一点?

Here is my jQuery script:这是我的 jQuery 脚本:

$(document).ready(function(){
    $("#query").keyup(function(){
            var query=$(this).val();
            var yt_url=''+selected.tab+'.php?q='+query;
            window.location.hash=''+selected.tab+'/'+query+'/';
            document.title=$(this).val()+" - My Search Script";
            if(query==''){
                  window.location.hash='';
                  document.title='My Search Script';
            }
            $.ajax({
                type:"GET",
                url:yt_url,
                dataType:"html",
                success:function(results){
                   $('#results').html(results);
                }
            });
    });
    if(window.location.hash.indexOf('#'+selected.tab+'/')==0){
        query = window.location.hash.replace('#'+selected.tab+'/', '').replace('/', '');
        $('#query').val(decodeURIComponent(query)).keyup();
    }
});

From your code, the selected variable seems to be global, so:从您的代码中, selected的变量似乎是全局的,所以:

<a id="change" href="#">change</a>
<script type="text/javascript">
$('#change').click(function() {
  selected.tab = "somethingelse";
});
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM