1. 程式人生 > >textarea標簽輸出內容時不能頂格(左對齊)輸出

textarea標簽輸出內容時不能頂格(左對齊)輸出

line ima getc pbo 不能 mono lac msu images

我用textarea輸出文本內容的時候出現下面的問題:文本內容在action裏測試沒有問題(文本內容前面沒有空格),但是在jsp頁面textare標簽中輸出文本內容時,文本內容前面卻出現一些多余的空格。

技術分享圖片

技術分享圖片

代碼如下:

[html] view plain copy
  1. <td>
  2. <textarea rows="8" cols="34" readonly="readonly">
  3. <%=MyTools.toChinese(myWord.getContent()) %
    >
  4. </textarea>
  5. </td>

經過查詢發現原因是<textarea>標簽會保留用戶的預定義格式,這樣寫瀏覽器會把<%%>之前的空格全部輸出!,所以,前面不要有空格,應該這樣寫:

[html] view plain copy
  1. <td><textarea rows="8" cols="34" readonly="readonly"><%=MyTools.toChinese(myWord.getContent()) %></textarea
    ></td>

技術分享圖片

textarea標簽輸出內容時不能頂格(左對齊)輸出