Authored by 阿达

品牌一览搜索js 代码bug

@@ -15,11 +15,11 @@ function getRanToken() { @@ -15,11 +15,11 @@ function getRanToken() {
15 /** 15 /**
16 * 增加单条记录 16 * 增加单条记录
17 */ 17 */
18 -function addHistory(brandId) { 18 +function addHistory(brandName) {
19 $.ajax({ 19 $.ajax({
20 type: 'GET', 20 type: 'GET',
21 url: '/category/brand/addBrandSearch', 21 url: '/category/brand/addBrandSearch',
22 - data: 'brandId=' + brandId, 22 + data: 'brandName=' + brandName,
23 success: function(data) { 23 success: function(data) {
24 }, 24 },
25 error: function() { 25 error: function() {
@@ -30,13 +30,11 @@ function addHistory(brandId) { @@ -30,13 +30,11 @@ function addHistory(brandId) {
30 //绑定提交前的存local操作 30 //绑定提交前的存local操作
31 function bindWirteLocal($brandList) { 31 function bindWirteLocal($brandList) {
32 $brandList.on('click', 'p', function(e) { 32 $brandList.on('click', 'p', function(e) {
33 - var a,brandName,brandId,url;  
34 - var query = brandName + url, 33 + var brandName,brandId,url;
  34 + var a = $(this).find('a');
  35 + var query = a.attr('brandName') + a.attr('href'),
35 historys; 36 historys;
36 37
37 - e.preventDefault();  
38 - a = $(this).find('a');  
39 -  
40 brandName = a.attr('brandName'); 38 brandName = a.attr('brandName');
41 39
42 brandId = a.attr('brandId'); 40 brandId = a.attr('brandId');
@@ -45,6 +43,14 @@ function bindWirteLocal($brandList) { @@ -45,6 +43,14 @@ function bindWirteLocal($brandList) {
45 43
46 44
47 45
  46 + e.preventDefault();
  47 +
  48 + if ($('.net-search').length > 0) {
  49 + addHistory(brandName);
  50 + location.href = url;
  51 + return;
  52 + }
  53 +
48 if (localStorage) { 54 if (localStorage) {
49 historys = localStorage.getItem('historys-brand'); 55 historys = localStorage.getItem('historys-brand');
50 56
@@ -64,9 +70,7 @@ function bindWirteLocal($brandList) { @@ -64,9 +70,7 @@ function bindWirteLocal($brandList) {
64 localStorage.setItem('historys-brand', historys); 70 localStorage.setItem('historys-brand', historys);
65 } 71 }
66 72
67 - if ($('.net-search').length > 0) {  
68 - addHistory(brandId);  
69 - } 73 +
70 74
71 location.href = url; 75 location.href = url;
72 }); 76 });
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
19 {{#if historySearch}} 19 {{#if historySearch}}
20 <div class="history-search net-search hide"> 20 <div class="history-search net-search hide">
21 <h3><span class="iconfont">&#xe64a;</span>最近搜索 21 <h3><span class="iconfont">&#xe64a;</span>最近搜索
22 - <button id="clear-history" class="clear-icon iconfont hide">&#xe64c;;</button> 22 + <button id="clear-history" class="clear-icon iconfont hide">&#xe64c;</button>
23 </h3> 23 </h3>
24 <ul class="history clearfix"> 24 <ul class="history clearfix">
25 {{# history}} 25 {{# history}}