字數計算
2019-12-18
上面的框可以拉長,直接輸入就會顯示字數,不會計算空白及換行,其餘皆計算進去。
程式碼如下
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<textarea id="str" col="1000" row="30"></textarea> | |
<div id="res"></div> | |
<script> | |
var str = document.getElementById('str'); | |
var res = document.getElementById('res'); | |
str.addEventListener('keyup',function(){ | |
res.innerHTML = str.value.trim().replace(/ /g,'').replace(/\n/g,'').length ; | |
}) | |
</script> |