[英]How to add send data from my database to a text area form in html
[英]How to limit my text area field to 1000 words in my html form
您好,我在創建的個人資料頁面上有一個關於我的字段,但注意到即使我的最大長度設置為 1000 字,我也無法從其他文檔中復制和粘貼單詞,當我復制並粘貼到文本區域時,它會包含50字左右。 我在數據庫中的大約長度設置為 2000。以下是我的表單中的內容。 非常感謝提供的任何幫助
<div class="form-group">
<label for="about">About Me</label>
<textarea name="about" rows="3" maxlength="1000" class="form-control" id="about"></textarea>
</div>
標簽maxlength
定義最大characters
數而不是最大字數。
也許您的文本超過 1000 個字符,所以它不起作用
maxlength 屬性定義用戶可以輸入或的最大字符數(作為 UTF-16 代碼單元)。
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/maxlength
當最大單詞數為 5 時,我創建了一個簡單的示例:
const input = document.getElementById('textArea'); const textContent = []; let maxWords = 5; function separateWords(text, e){ let words = text.split(" "); if (words.length >= maxWords + 1) { input.setAttribute('maxLength',words.join(" ").length - 1); return words.join(" ").trim(); } else { return words.join(" "); } }; input.addEventListener('input', function() { console.log(separateWords(input.value)); });
<div> <p> Type something (max 5 words): </p> <textarea id="textArea" value=""></textarea> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.