[jQuery] [ask] bind and unbind
hello everyone,
i'm new here my name is roy.
to the point, I'm facing a problem when implementing jQuery. and this
is the code :
=============================================================
<script type="text/javascript">
function check(){
var nx = $(':checkbox:checked').val().length;
var nc = $(':checkbox:checked').length;
//alert(nx)
function alert1(){alert('Alert 1')}
function alert2(){alert('Alert 2')}
if(nc!=0){
if(nx <= 15){
$('.link_detail.button_format').attr('onClick','').click(alert1);
$('.link_new.button_format').attr('href',"http://localhost/add.php?
ref="+$(':checkbox:checked').val());
}else{
$('.link_detail.button_format').unbind('click',alert1).attr
('href',"http://localhost/detail.php?ref="+$(':checkbox:checked').val
());
$('.link_new.button_format').attr('onClick','').click(alert2);
}
}
}
check();
$(':checkbox').click(check());
</script>
<a href="#" class="link_detail button_format">detail</a>
<a href="#" class="link_new button_format">new</a>
<table width="100%" class="tabledata" id="tabledata">
<tr>
<td width="10px"></td>
<td><strong>ID</td>
<td><strong>Name</td>
</tr>
<tr>
<td><input type="checkbox" value="veryverylongvalues"
onclick="check()"></td>
<td>1</td>
<td>Me</td>
</tr>
<tr>
<td><input type="checkbox" value="shortervalues"
onclick="check()"></td>
<td>2</td>
<td>You</td>
</tr>
</table>
==================================================================
what i want is :
- if i checked a checkbox that have value length less than 15 (id =2)
the new link can be cliked, and the detail link will show alert (no
problem)
- if i checked a checkbox that have value length more than 15 (id =1)
the detail link can be cliked, and the new link will show alert (no
problem)
the problem occur when :
1. i check checkbox with val length less than 15 (id =2) and click
detail, it shows alert (no problem here)
2. the i uncheck previous checkbox (id =2), and check other checkbox
(id =1) and then when i click detail the alert show again (here the
problem).
can anyone solve this?