Textarea Maxlength
The purpose of my script is not to enforce the maximum length, though it can easily be changed to do that. However, I decided to restrict my script to giving a polite reminder when the user exceeds the maximum amount of characters. Actually enforcing this maximum length is left to the trim_to attribute of Movable Type, which, being a server side functionality, is impossible for users to turn off.
- textarea是沒有maxlen屬性的, 不過我們可以用javascript來implement, 不過目前市面上的作法通常是取substring(0, textarea.getAttribute('maxlen'))之類的, 這樣做法有一個缺點: 在IE會一直focus到textarea內文最後的地方。
- 再者, javascript很容易可以被disable掉, 無法提供一個安全的限制, 只能拿來當作提醒的用途, 在這篇文章中, ppk建議的方法是: 超過maxlen的話, 提示他就好了, 紅色的字之類的
- 注意文中
counterClone.relatedElement = x[i];
取得reference之後就bind在relatedElement裡面, 方便之後的access, 不需要每次都去取reference
沒有留言:
張貼留言