本文實例講述了jQuery自動添加表單項的方法。分享給大家供大家參考。具體如下:
這裡實現通過點擊按鈕動態添加一個表單輸入項
<script type="text/javascript" charset="utf-8"> $(function() { var fieldCount = 1; $("#addFieldButton").click(function() { fieldCount++; if(fieldCount <= 5) { var fieldID = "recipient_email_" + fieldCount; $("#additionalEmails").append("<label for='"+fieldID+"'>Recipient Email "+fieldCount+": </label>"+ "<input type='text' name='"+fieldID+"' " + "id='"+fieldID+"' size='30'><br />" ); } else { alert("Maximum email fields reached."); } }); }); </script>
希望本文所述對大家的jquery程序設計有所幫助。