2012-05-13 49 views
1

我試圖將文本添加到一個div sectionj使用jquery,但文雲我期望的div外面..我的HTML看起來像:jQuery的文本追加了DIV部分的

<!--CONTENT AREA--> 
<div id="content"> 
    <div id="content_inner"> 
    <h2 id='titulo'>BUSCAR:</h2> 
    KEYWORDS: 
    <input type='text' id='paramsQuery'> 
    <input type='submit' id='botonBuscar' value='buscar'> 
    <div id='results'></div> 
    </div> 
</div> 

我的js函數看起來像這:

$(document).ready(function() { 
    $("#botonBuscar").click(function() { 
    var params = $("#paramsQuery").val(); 
    $("#column3_inner").append(params); 
    }); 
}); 

任何建議,使文本保持所需的寬度?

+0

這裏是'column3_inner'? –

+0

我想你在這裏錯過了一些HTML,請提供相關的HTML代碼,有一個很好的! –

+0

請告訴我們完整的代碼。您的示例中有'column3_inner' div。 –

回答

2

您將結果添加到不在提供的代碼中的元素。也許你打算把它放在#results呢?

$(function() { 
    $("#botonBuscar").on("click", function() { 
    $("#results").append($("#paramsQuery").val()); 
    }); 
}); 

演示:http://jsbin.com/icapuh/edit#javascript,html

如果您的文本滿溢你的盒子,你可以有幾種選擇那裏。你可以打破行:

#results { 
    word-wrap: break-word; 
} 

或者,你可能會導致滾動:

#results { 
    overflow-x: scroll; 
} 

或設置text-overflow透露省略號:

#results { 
    overflow: hidden; 
    text-overflow: ellipsis; 
    -o-text-overflow: ellipsis; 
    -ms-text-overflow: ellipsis; 
} 
+0

Saweet + 1閱讀調查問卷介紹:))**演示** http://jsfiddle.net/qW8Fq/ –

+0

對不起,我的錯誤它實際上就像你說的ut我仍然有同樣的問題....文本寬度超過了我的div寬度 –

+0

@ user1391791在'#results'元素上設置'word-wrap'或'overflow-x'。 – Sampson