//複選選擇後出現輸入框 or 下拉 (function($) { $.fn.typeCheck = function(data){ var other = this, otherText = this.children('input[type="text"]'), otherCheckbox = this.children('input[type="checkbox"]'); otherText.attr('disabled','true'); //預設無法輸入 this.addClass('other'); //新增 other 的 class otherCheckbox.on('change' , function() { //當元素的值發生改變 if (otherCheckbox.is(":checked")) { //如果 checkbox 被勾選 otherText.prop('disabled',false).focus(); } else { otherText.attr('disabled','true').val(''); //未勾選,按鈕不能執行 } }).change(); }; })(jQuery); //單選選擇後出現輸入框 or 下拉 (function($) { $.fn.typeRadio = function(data){ var rad = this.find('input[type="radio"]'), total = rad.length, otherText = this.find('input[type="text"] ,select'), otherSelect = this.find('select'); otherText.parents('li').addClass('other'); //有輸入框的項目,套入 CSS otherText.attr('disabled',true); //預設關閉輸入 for( var i = 0; i < rad.length; i++ ) { rad[i].onclick = function() { // 文字欄位 otherText.attr('disabled',true); //先讓其他的關閉輸入 $(this).parent('li').find('input[type="text"] ,select').attr('disabled',false).focus(); //把自己的輸入開啟 }; } }; })(jQuery);