I have a Google style instant search script written in jQuery which pulls results from a PHP script. 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. How can I do this?
Here is my jQuery script:
$(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:
<a id="change" href="#">change</a>
<script type="text/javascript">
$('#change').click(function() {
selected.tab = "somethingelse";
});
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.