2013-06-18 80 views
0

此代碼有什麼問題,在編輯內聯時,我無法在下拉框中選擇值?無法在下拉框中選擇值(內聯編輯)

我只是做這個用的文本框,但是在這種情況下,我想用一個下拉選項,然後選擇它的價值...

<table cellpadding="2" cellspacing="0" border="0" width="100%" id="tblMain" class="edit"> 
    <tr> 
     <td>Edit this:</td> 
     <td class="edit shift<?php echo " ".$row['ctrID']?>"><?=$row['shift']?></td> 
    </tr> 
</table> 

這裏是JS:

<script> 
$(document).ready(function(){  

    $('td.edit').click(function(){ 
       $('.ajax').html($('.ajax input').val()); 
       $('.ajax').removeClass('ajax'); 
       $(this).addClass('ajax'); 

       // this is the part i am having a trouble with: 

       $(this).html('<select id="editbox" size="'+$(this).text().length+'"><?php while($row = mysql_fetch_assoc($editShift)){ ?><option value="' + $(this).text() + '"><?=$row['shiftCode']?></option><?php } ?></select>'); 
       $('#editbox').focus(); 
    }); 

    $('#editbox').live('blur',function(){ 
       $('.ajax').html($('.ajax input').val()); 
       $('.ajax').removeClass('ajax'); 
    }); 
}); 

$('td.edit').keydown(function(event){ 
      arr = $(this).attr('class').split(" "); 
      if(event.which == 13) 
        { 
      $.ajax({type: "POST", 
      url: "get.php", 
      data: "value="+$('.ajax input').val()+"&rownum="+arr[2]+"&field="+arr[1], 
      success: function(data){ 
       $('.ajax').html($('.ajax input').val()); 
       $('.ajax').removeClass('ajax'); 
           }}); 
        } 
}); 

</script> 

回答

0

每點擊td進行分類編輯,

下拉標記正在替換td 下面的行

$(this).html('<select id="editbox">...</select>'); 

,這樣你們可以檢查,如果選擇下拉列表中td..then內已經插入跳過插入標記

if($(this).find("#editbox").size() == 0) 
      { 

      // drop down markup will come here 

      }