2012-07-17 98 views
0

有一些代碼:如何從表中textarea的右側對齊按鈕?

 $('.field').live({ 
      mouseenter: 
       function() 
       { 
        old_value=$(this).text(); 
        item_id=$(this).attr('id'); 
        item=$(this).parent('td'); 
        //height=item.attr('height'); 
        height=event.target.parentNode.offsetHeight; 
        width=event.target.parentNode.offsetWidth; 
        //$(event.target).replaceWith('<textarea id="current-editor"></textarea>'); 
        //$("#current-editor").height(height-10); 
        new_value=(old_value=='Not translated') ? '' : old_value; 
        $(this).empty(); 
        var field="<textarea style='vertical-align: middle; font-family: Helvetica; font-size: 12pt;' id='new_value' name='term'>" + new_value + "</textarea><div id='save_button' class='btn btn-primary' style='float: right' href='#'>Save</div>"; 
        $(this).html(field); 
        $("#new_value").height(height); 
        $("#new_value").width(width); 
        button_id=item_id.split('/')[0]; 
        button_id=button_id.replace(/([!"#$%&'()*+,./:;<=>[email protected]\[\\\]^`{|}~])/g, "\\$1"); 
        $("#"+button_id).show(); 
       }, 
      mouseleave: 
       function() 
       { 
        $(this).empty(); 
        $(this).html(old_value); 
        $("#"+button_id).hide(); 
       } 
      } 
     ); 

和代碼爲「田」:

echo "<td width='200' style='vertical-align: middle;'><div class='field' id='".$record['translate']['label_value']."/".$record['language_id']."'>". 
strip_tags($record['translate']['coalesce(loc.language_value)'])."</div>"; 

所以,表格的單元格的這個代碼更改文本內容到textarea的,和它的作品。但是我需要在textarea後添加「保存」按鈕,它也可以工作。按鈕是在新行(因爲textarea必須有100%的寬度),但我需要按鈕和textarea在同一行。請告訴我,我該怎麼做?

回答

0

設置寬度textarea的和float:離開它, 試試這個

var field="<textarea style='vertical-align: middle; float:left; width:250px; font-family: Helvetica; font-size: 12pt;' id='new_value' name='term'>" + new_value + "</textarea><div id='save_button' class='btn btn-primary' style='float: right' href='#'>Save</div>"; 
+0

很抱歉,但它不工作。我有1個想法:我試圖使用這個命令:item.width(item.width()+ 50),但是我需要爲class ='abc'的所有項目增加寬度。我該怎麼做? – user1517541 2012-07-17 07:32:42

+0

$('。abc')。width(new-width) – vikrantx 2012-07-17 08:10:58