iT邦幫忙

0

HTML 語法 遇到空格就換行

  • 分享至 

  • twitterImage

各位大大好,想請問在HTML語法上面有辦法去做到遇到空格或是遇到括弧 "()" 就換行嗎??

froce iT邦大師 1 級 ‧ 2018-05-08 09:43:57 檢舉
HTML不可能,Javascript可以。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

3
cbg1554f4
iT邦見習生 ‧ 2018-05-08 10:34:27
最佳解答

Html只負責輸出畫面,對於空白或括弧沒有處理語法,所以得由第三方網頁程式(JavaSript、C#等)將空白或特定字元轉成換行碼後交給HTML顯示。

0
暐翰
iT邦大師 1 級 ‧ 2018-05-08 11:40:41
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
    	var text = $("body").html();
        var text2 = $("body").val();
        $("body").html(text.replace(" ","<br>").replace(")",")<br>"));
    });
});
</script>
</head>
<body>
    Hello (IT邦幫忙) ~ 
    <button>換行</button>
</body>
</html>

一開始畫面 :

按完按鈕(替代字串) :


簡單概念提供給你 :)

看更多先前的回應...收起先前的回應...

這種情況會有問題,有太多需要考慮的東西
/images/emoticon/emoticon10.gif

<div class="content">
    The value for each key is a function (or false value) that is used as the handler instead of the (or true value) final argument to the method
</div>
froce iT邦大師 1 級 ‧ 2018-05-08 12:02:00 檢舉

用keyup事件在觸發的時候,把最後要替換的字元做替換就行。
不用這麼麻煩。

沒說是輸入時的內容吧,應該是掃過整個html頁面做處理~
/images/emoticon/emoticon10.gif

小火車 iT邦新手 4 級 ‧ 2018-05-08 14:05:08 檢舉

感謝各位大大的分享與建議

我要發表回答

立即登入回答