HỏiMọi người giúp xem code này lỗi ở đâu

39 bài đăng
21.11.2017 / 12:43
saoko
Bài đăng: 1449
Member
MXH Vườn Cảm Xúc

{%if get_get('b2') and b3|length>2%} là có giá trị của select 2 trên url và select 3 có giá trị để chọn thì hiển thị select 3. Như cái thể loại công nghệ thì select 2 ko có giá trị để chọn nên nó ko hiện

21.11.2017 / 15:06
saoko
Bài đăng: 1449
Member
MXH Vườn Cảm Xúc

Code ngắn hơn, nhìn dễ hiểu hơn nè

TWIG
  1. {%set b1=['Công nghệ','Quần áo']%}
  2. {%set b2=['Quần','Áo']%}
  3. <script src="http://code.jquery.com/jquery-latest.js"></script>
  4. <div id="idlb"><form method="post">
  5. <select name="b1" id="b1" onchange="lb()"><option value="">Không</option>{%for i in 0..b1|length-1%}<option{%if get_get('b1')==b1[i]%} selected="selected"{%endif%}>{{b1[i]}}</option>{%endfor%}</select>
  6. {%if get_get('b1')%}<select name="b2" id="b2" onchange="lb()"><option value="">Không</option>{%for i in 0..b2|length-1%}<option{%if get_get('b2')==b2[i]%} selected="selected"{%endif%}>{{b2[i]}}</option>{%endfor%}</select>{%endif%}</form>
  7. <script>function lb(){$("#idlb").load('/test?b1='+encodeURI(b1.value)+{%if get_get('b1')%}'&b2='+encodeURI(b2.value)+{%endif%}' #idlb')}</script></div>
Đã chỉnh sửa. saoko (21.11.2017 / 15:09)
21.11.2017 / 16:54
mad
Bài đăng: 2434
Member
Nhào vô cắn tao đi, tao sợ mày à cắn bừa.

Thay i trong for b2 thành j xem

21.11.2017 / 16:55
mad
Bài đăng: 2434
Member
Nhào vô cắn tao đi, tao sợ mày à cắn bừa.

Và load ko thể load script đc

21.11.2017 / 16:56
mad
Bài đăng: 2434
Member
Nhào vô cắn tao đi, tao sợ mày à cắn bừa.

Nên để nó bên ngoài vd tí chỉ cho giờ dùng phone r

21.11.2017 / 18:53
saoko
Bài đăng: 1449
Member
MXH Vườn Cảm Xúc
mad đã viết

Nên để nó bên ngoài vd tí chỉ cho giờ dùng phone r

Để ngoài thì nó ko thực, phải dùng js để đặt điều kiện, cũng thử rồi mà vẫn ko được

21.11.2017 / 19:12
mad
Bài đăng: 2434
Member
Nhào vô cắn tao đi, tao sợ mày à cắn bừa.

đặt trong select là data-id="1" 2 gì đó, rùi khi onchange thì nó get data select 2

21.11.2017 / 19:14
saoko
Bài đăng: 1449
Member
MXH Vườn Cảm Xúc

Đưa ra ngoài thì tui viết như thế này

TWIG
  1. {%set b1=['Công nghệ','Quần áo']%}
  2. {%set b2=['Quần','Áo']%}
  3. <script src="http://code.jquery.com/jquery-latest.js"></script>
  4. <div id="idlb"><form method="post"><select name="b1" id="b1" onchange="lb()"><option value="">Không</option>{%for i in 0..b1|length-1%}<option{%if get_get('b1') and get_get('b1')==b1[i]%} selected="selected"{%endif%}>{{b1[i]}}</option>{%endfor%}</select>
  5. {%if get_get('b1')%}<select name="b2" id="b2" onchange="lb()"><option value="">Không</option>{%for j in 0..b2|length-1%}<option{%if get_get('b2') and get_get('b2')==b2[j]%} selected="selected"{%endif%}>{{b2[j]}}</option>{%endfor%}</select>{%endif%}</form></div>
  6.  
  7. <script>function lb(){if(b1.value){b1=encodeURI(b1.value)};if(b2.value){b2=encodeURI(b2.value)};$("#idlb").load('/test?b1='+b1+'&b2='+b2+' #idlb')}</script>

Ko biết lỗi ở đâu mà nó liệt cái load trang luôn

21.11.2017 / 19:15
saoko
Bài đăng: 1449
Member
MXH Vườn Cảm Xúc
mad đã viết

đặt trong select là data-id="1" 2 gì đó, rùi khi onchange thì nó get data select 2

Dữ liệu thì có ra rồi đó mà nó ko chọn

21.11.2017 / 19:26
mad
Bài đăng: 2434
Member
Nhào vô cắn tao đi, tao sợ mày à cắn bừa.

<script>

url='';

function run(){

$('select').unbind().change(function(){

if($(this).attr('data-id')==1){

url='test.php?b1='+$(this).val();

}else{

arr_ur='';

tag_ur='';

for(i=1;i<$(this).attr('data-id');i++){

if(i>1){

tag_ur='&';

}

arr_ur+=tag_ur+'b'+i+'='+$('select:eq('+(i-1)+')').val();

}

url='test.php?'+arr_ur;

}

$.get(url,function(){

$('id refresh').html($(this).find('id refresh').html());

run();

})

})

}

run();

</script>