jQuery:通过选择SELECT OPTION克隆元素

| 我有一个选择,可以选择用户拥有多少辆汽车。之后,他/她将获得与INPUT相同数量的DIV,以描述什么型号等。 如何使用SELECT复制包含INPUT的DIV?
已邀请:
这应该给您大致的想法...
$(\'select#cars\').change(function() {
   // Get number of cars chosen
   var carsCount = $(this).val(),
       // Get a reference to the first input group so we can clone it
       carInput = $(\'#car-inputs div:first\');

   // Clone per number chosen
   for (var i = 0; i < carsCount; i++) {
       // Insert clone after original.
       // IRL, you probably need to do some preprocessing on it first.
       carInput.clone().insertAfter(carInput);
   }
});
也许克隆可以帮助您:http://api.jquery.com/clone/ 希望这可以帮助。

要回复问题请先登录注册