**** Code:
<form action="http://baodiaoc.vn/tim-kiem/mua" method="POST" class="head-search" name="suggestion">
<center><h1>Tìm kiếm ngôi nhà bạn yêu thích</h1></center>
<div class="sort-home">
<button class="r-n-d" type="button" data-value="mua" name="search">
<span class="display-type">
Mua nhà đất
</span>
<span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span>
</button>
<ul class="suggest-result" style="display: none;">
<li style="display: block;">
<a href="http://baodiaoc.vn/tim-kiem/thue" data-value="thue" name="search">
<span>Thuê nhà đất</span>
</a>
</li>
<li style="display: none;">
<a href="http://baodiaoc.vn/tim-kiem/mua" data-value="mua" name="search">
<span>Mua nhà đất</span>
</a>
</li>
</ul>
</div>
<input class="form-control search-text" id="" required="required" placeholder="Nhập tên quận, đường, khu dân cư hoặc tòa nhà" value="" type="text">
<button class="glyphicon glyphicon-search search-submit" aria-hidden="true" type="submit"></button>
</form>
**** JS
jQuery(document).ready(function($) {
var that = this;
var $suggestInp = $("form[name=suggestion] input");
var $typeDropdown = $("form[name=suggestion] .sort-home button");
var $typePopup = $("form[name=suggestion] .sort-home .suggest-result");
var $suggestResult = $(".suggest-result.suggestion");
var $suggestForm = $("form[name=suggestion]");
var SUGGEST_INTERVAL = 400;
$("form[name=suggestion] .sort-home button").click(function(e) {
e.preventDefault();
if ($(this).next().css("display") === "block"){
$("form[name=suggestion] .sort-home .suggest-result").css("display", "none");
}else{
$("form[name=suggestion] .sort-home .suggest-result").css("display", "block");
}
});
$typePopup.find("a[data-value=" + $typeDropdown.attr("data-value") + "]").parent().css("display", "none");
$typePopup.find("a").click(function(e) {
e.preventDefault();
var $this = $(this);
$typePopup.find("li").css("display", "block");
$this.parent().css("display", "none");
$typeDropdown.attr("data-value", $this.attr("data-value"));
$typeDropdown.find(".display-type").text($this.text());
$suggestForm.attr("action", $this.attr("href"));
$typePopup.css("display", "none");
});
});

Không có nhận xét nào:
Đăng nhận xét