{%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
HỏiMọi người giúp xem code này lỗi ở đâu
Code ngắn hơn, nhìn dễ hiểu hơn nè
{%set b1=['Công nghệ','Quần áo']%} {%set b2=['Quần','Áo']%} <script src="http://code.jquery.com/jquery-latest.js"></script> <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')==b1[i]%} selected="selected"{%endif%}>{{b1[i]}}</option>{%endfor%}</select> {%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> <script>function lb(){$("#idlb").load('/test?b1='+encodeURI(b1.value)+{%if get_get('b1')%}'&b2='+encodeURI(b2.value)+{%endif%}' #idlb')}</script></div>
Thay i trong for b2 thành j xem
Và load ko thể load script đc
Nên để nó bên ngoài vd tí chỉ cho giờ dùng phone r
đặt trong select là data-id="1" 2 gì đó, rùi khi onchange thì nó get data select 2
Đưa ra ngoài thì tui viết như thế này
{%set b1=['Công nghệ','Quần áo']%} {%set b2=['Quần','Áo']%} <script src="http://code.jquery.com/jquery-latest.js"></script> <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> {%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> <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
<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>
![[OFF]](/assets/images/off.gif)