我必须在此网站中创建搜索引擎:http://olx.co.id。它有三个关键字。首先是按项目搜索,第二个是按城市搜索,第三个是按类别搜索。用户可以使用一个关键字,两个关键字和三个关键字进行搜索。我没有任何想法这样做。这是我的代码,但我不确定它是否运行良好。
<form method="GET" action="category-grid.php">
<div class="control-group">
<input type="text" name="search_item_" class="search-field" placeholder="Searching Item ..." />
<ul class="categories-filter animate-dropdown">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" >All Cities</button>
<ul class="dropdown-menu" role="menu" id="city" >
<li role="presentation"><a role="menuitem" tabindex="-1" >Jakarta</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" >Singapore</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" >Beijing</a></li>
</ul>
</li>
</ul>
<ul class="categories-filter animate-dropdown">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">All Categories</a>
<ul class="dropdown-menu" role="menu" id="category">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Car</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Motorcycle</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Property</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Industry</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Elektronic & Gadget</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">Sport</a></li>
</ul>
</li>
</ul>
<a class="search-button" href="<?php echo base_url();?>search" ></a>
</div>
</form>
我的问题是如何在用户更改城市的价值时获取类别的值,或者在用户更改类别的值时获取城市的价值。
<script>
var city; var category; var item=$('search_item').val();
$('#city li').on('click', function(){
city = $(this).text();
if(category == "") window.location.assign('<?php echo base_url()?>index.php/searching/'+city);
else window.location.assign('<?php echo base_url()?>index.php/searching/'+city+'/'+category);
});
$('#category li').on('click',function(){
$category = $(this).text();
if(city == "") window.location.assign('<?php echo base_url()?>index.php/searching/'+category);
else window.location.assign('<?php echo base_url()?>index.php/searching/'+lokasi+'/'+kategori);
});
<script>
感谢所有评论和回答