簡體   English   中英

復選框多次選中以選擇值

[英]checkbox checked multiple time for selecting value

我有一個復選框,當設置為true時,必須禁用其他文本框。 這里真正的問題是,僅當我第一次單擊兩次時,復選框才會更改值。 第一次,我必須單擊兩次以禁用其他文本框。 否則就可以正常工作。 在這里,我給了我的jquery函數:

function bundlecheckout(val,total)
{ 

   $("#file_check"+val).click(function() {
        $('input[id^="file_check"]').attr("checked", false);
        //$("#file_check"+val).unbind('click');
        $(this).attr('checked', true);
        $("#checkout").attr("disabled", !this.checked);
        for(i=0;i<=total+1;i++)
        {             
            if(i !=val ){           
            $("#txtinstruction"+i).attr("disabled", this.checked);
            $("#txturl"+i).attr("disabled", this.checked);
        }
        else{
            $("#txtinstruction"+i).removeAttr("disabled");
            $("#txturl"+i).removeAttr("disabled");
            }
        }   
   }    
);}

復選框元素

<input type="checkbox" class="file_check" name="file_upload_check" value="<?php echo $testing_type_id;?>" id="file_check<?php echo $testing_type_id;?>" onclick="bundlecheckout(<?php echo $testing_type_id;?>,<?php echo $total ?>);"/>Apply<br />

試試下面的代碼。 我不知道您為什么要在點擊本身上綁定點擊事件。

function bundlecheckout(val,total,e)
    { 
            $('input[id^="file_check"]').attr("checked", false);
            //$("#file_check"+val).unbind('click');
            $(e).attr('checked', true);
            $("#checkout").attr("disabled", !this.checked);
            for(i=0;i<=total+1;i++)
            {             
                if(i !=val ){           
                $("#txtinstruction"+i).attr("disabled", this.checked);
                $("#txturl"+i).attr("disabled", this.checked);
            }
            else{
                $("#txtinstruction"+i).removeAttr("disabled");
                $("#txturl"+i).removeAttr("disabled");
                }
            }   
      }
<input type="checkbox" class="file_check" name="file_upload_check" value="<?php echo $testing_type_id;?>" id="file_check<?php echo $testing_type_id;?>" onclick="bundlecheckout(<?php echo $testing_type_id;?>,<?php echo $total ?>,this);"/>Apply<br />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM