jQuery實現根據類型自動顯示和隱藏表單

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

html

代碼如下:

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

 

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);
       &nbsnbsp;    input_type.on('change',typeChangeHandle);
            input_type=null;

 

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

You May Also Like