0
基本上我有至少20個或更多按鈕和textareas像這些不同的類名稱。如何將DRY方法應用於多個jQuery按鈕切換
<textarea class="widefat res_editor_exp2wid1" rows="10" cols="20" style="display: none;" id="<?php echo $this->get_field_id('jd1'); ?>" name="<?php echo $this->get_field_name('jd1'); ?>"><?php echo esc_attr($instance['jd1']); ?></textarea>
<button class="res_editor_btn_exp2wid1" type="button">Edit Content</button>
我在做什麼是點擊按鈕後擴大textarea的。通過做 -
jQuery(document).on('click', '.res_editor_btn_exp2wid1', function(){
jQuery(".res_editor_exp2wid1").toggle("slow").click(function(){
jQuery('.res_editor_exp2wid1').trumbowyg();
});
});
每次我必須寫這個jQuery這有點煩人,我想使它成爲一個乾的方法。我如何才能做到這一點?對不起如果這聽起來很荒謬,我在這件事上很新手。任何幫助,將不勝感激。
感謝您的評論,我會盡力實現這一點,並與您取得聯繫 –