2014-05-06 39 views
0

我需要添加更多元素到使用jquery的文本框中,然後才能插入到數據庫中。因此,當我想添加一個被刪除的文本框時,此腳本在文本框中添加一個元素...如何在文本框中添加一個以上的元素??幫助 jQuery的將元素拖放到文本框中html

<script type="text/javascript"> 
$(function() { 
$(".draggable").draggable({ 
    revert: true, 
    helper: 'clone', 
    start: function(event, ui) { 
     $(this).fadeTo('fast', 0.5); 
    }, 
    stop: function(event, ui) { 
     $(this).fadeTo(0, 1); 
    } 
}); 

$("#tag").droppable({ 
    hoverClass: 'active', 
    drop: function(event, ui) { 
     this.value = $(ui.draggable).text(); 
    } 
}); 
}); 

PHP/HTML代碼

<p><b>Tags:</b></p>  
     <input type="text" name="tag" id="tag" style="width:605px"> 
       <?php if($tags): ?> 
        <?php foreach($tags as $t): ?> 
         <div class="draggable" style="border:1px solid green;width:100px;height:30px;display:inline-block;background-color:#e6eaff;cursor:default;font-size:18px;"> 
          <a href="#" class="tg1" id="<?php echo $t['id']?>" ><?php echo $t['name'] ?></a> 
         </div> 
        <?php endforeach; ?> 
       <?php endif; ?>     
     <br /> 

我想不止一個元素在文本框中添加

+0

你的問題是什麼? –

+0

我編輯了我的問題 – user3588247

回答

0

只是「讀取」文本框裏面的當前文本到一個變量,

$("#mytextarea").val() 

然後「合併」將其與新的內容到另一個變量,然後這個新變量的內容拖放到文本字段。

+0

我不明白朋友... – user3588247