yii架構下使用bootstrap時,判斷checkbox、radioButtonList和dropDownList的js方法

來源:互聯網
上載者:User

標籤:style   java   使用   io   strong   for   ar   cti   

1、首先設定button按鈕的id:

<span style="font-size:14px;">'htmlOptions'=>array('id'=>'buttonStateful')</span>

例如:

<span style="font-size:14px;">        <?php            $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'type'=>'primary', 'label'=>'提交', 'htmlOptions'=>array('id'=>'buttonStateful')));         ?></span>


2、對checkbox是否選中和選中值判定

<span style="font-size:14px;"><script type="text/javascript">$('#buttonStateful').click(function(){    var cblists = $("[id *= Tice_modules]");    var module= '';    for (var i=0; i<cblists.length; i++) {        if (cblists[i].checked) {            if (module != ''){                module += ',';            }            module += cblists[i].value;        }    }if(module){url = "/controller/action?id=<?php echo $_GET['id'];?>&module=" + module;window.location.href = url;}else{alert('先選擇模組');}});</script> </span>


3、對checkbox是否選中判定

<span style="font-size:14px;"><script type="text/javascript">$('#buttonStateful').click(function(){        var location = $("[id *= unit_location]");    var result = false;    for (var i = 0; i < location.length; i++) {        if (location[i].checked) {            result = true;            break;                         }    }    if(result == false){alert('請選擇Unit Location');    }});</script> </span>

4、判斷dropDownList中選中了哪一個

<span style="font-size:14px;"><script type="text/javascript">$('#buttonStateful').click(function() {module = $('#theproject').find('option:selected').text();if (module){var btn = $(this);    btn.button('loading'); // call the loading functionurl = '/controller/action?id=<?php echo $id;?>&module=' + module;window.location.href=url;}else{alert('先選擇模組');}});</script> </span>



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.