var labels=['family','given','phone','occupation']; $.map(labels,function(obj) { $('<label />').attr('for',obj).text(obj) .appendTo('div#enquete'); $('<input size="20" />').attr({ 'id':obj,'name':obj}) .appendTo('div#enquete'); $('<br />').appendTo('div#enquete'); } ); //これ以降はラベルを日本語に変換(以下をはずずと英語で表示) var labels_ja={'family':'姓','given':'名','phone':'電話番号','occupation':'職業'}; $('label').each( function() { $(this).text(labels_ja[$(this).attr('for')]); } );
<form action="javascript:void(0);"> <div id="enquete"> </div> </form>
<form action="javascript:void(0);"> <div id="enquete"> <label for="family">family</label> <input size="20" id="family" name="family"><br /> <label for="given">given</label> <input size="20" id="given" name="given"><br /> <label for="phone">phone</label> <input size="20" id="phone" name="phone"><br /> <label for="occupation">occupation</label> <input size="20" id="occupation" name="occupation"><br /> </div> </form>