DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> jQuery實現根據類型自動顯示和隱藏表單
jQuery實現根據類型自動顯示和隱藏表單
編輯:JQuery特效代碼     

jquery實現表單根據單選按鈕進行字段的動畫切換,昨天寫的,感覺比起初學時寫的js/jquery有了很大進步。。在最大化擴展性的情況下經可能使代碼精簡。

html

代碼如下:
<div class="control-group">
                    <label class="control-label">類型:</label>
                    <div class="controls control-row-auto" id="type">
                    </div>
                    <span class="auxiliary-text"></span>
                </div>
                <div class="control-group ctype ctype1 ctype2">
                    <label class="control-label">欄目模版:</label>
                    <div class="controls">
                        <select name="column_tpl" class="input">
                        </select>
                    </div>
                    <span class="auxiliary-text"></span>
                </div>
                <div class="control-group ctype ctype1">
                    <label class="control-label">文章模版:</label>
                    <div class="controls">
                        <select name="article_tpl" class="input">
                        </select>
                    </div>
                    <span class="auxiliary-text"></span>
                </div>
                <input type="hidden" name="tpl" id="tpl" value="" />
                <div class="control-group ctype ctype3" style="display: none;">
                    <label class="control-label"><s>*</s>欄目鏈接:</label>
                    <div class="controls">
                        <input name="url" type="text" class="input-large" data-rules="{required:true,minlength:1,maxlength:30}">
                    </div>
                    <span class="auxiliary-text">內部鏈接格式:模塊/控制器/方法...,外部鏈接格式:http://../../</span>
                </div>

js

代碼如下:
//根據類型自動顯示和隱藏表單
            var input_type=$('input[name=type]');
            function typeChangeHandle(){
                var ctypes=$('.ctype');
                var type=$(this).val();
                var hideCtypes=ctypes.filter(':not(.ctype'+type+')').slideUp(500,function () {
                    $('.ctype'+type).slideDown(500);
                });
            }
            typeChangeHandle.apply(input_type);
            input_type.on('change',typeChangeHandle);
            input_type=null;

以上所述就是本文的全部內容了,希望大家能夠喜歡。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved