2

jQuery

$(function(){
 $('#4').click(function() {
 $('<input name="if4" type="text" value="other price>"').insertBefore('form textarea');
   });
 });

html

    <form>
< input name="name" type="text" value="Enter your name" /><br />
< input name="contacts" type="text" value="Contact info" /><br />
< select name="services">
< option value="1">1</option>
< option value="2">2</option>
< option value="3">3</option>
< option id="4" value="Other">4</option>
< /select><br />
< textarea name="description">Description</textarea><br />
< /form>

还有一个关于它的问题,当我按选项 4 两次时,出现 2 个新字段,有什么办法可以解决它,新字段只出现 1 次,第一次单击后?

4

1 回答 1

3
$(function(){
 $('#4').one('click', function() {
  $('<input name="if4" type="text" value="other price>"').insertBefore('form textarea');
 });
});
于 2010-04-14T09:55:52.313 回答