FBJS 文本区域倒计时
我在 Facebook 应用程序中有一个 textarea 元素,我想在视觉上限制一定数量的字符。这是我从网上获得的代码片段:
<script>
function textCounter(textarea, countdown, maxlimit)
{
textareaid = "ta1";
if (textareaid.value.length > maxlimit)
textareaid.value = textareaid.value.substring(0, maxlimit);
else
document.getElementById(countdown).value = '('+(maxlimit-textareaid.value.length)+' characters available)';
}
</script>
<form>
<textarea id="ta1" name="ta1" rows=5 cols=20
onKeyDown="textCounter('ta1','ta1count',100);"
onKeyUp="textCounter('ta1','ta1count',100);"
></textarea>
<br/>
<input id="ta1count" readonly type="text" size="30"/>
</form>
<script type="text/javascript">
textCounter('ta1','ta1count',100);
</script>
此脚本在 Facebook 框架之外运行良好,但我不明白 FBJS 的限制以及我需要更改哪些内容才能使此脚本正常工作。有没有人成功实现类似的功能?
谢谢。
I have a textarea element in a Facebook application I want to limit, visually, to a certain number of characters. This is a code snippet I got from the web:
<script>
function textCounter(textarea, countdown, maxlimit)
{
textareaid = "ta1";
if (textareaid.value.length > maxlimit)
textareaid.value = textareaid.value.substring(0, maxlimit);
else
document.getElementById(countdown).value = '('+(maxlimit-textareaid.value.length)+' characters available)';
}
</script>
<form>
<textarea id="ta1" name="ta1" rows=5 cols=20
onKeyDown="textCounter('ta1','ta1count',100);"
onKeyUp="textCounter('ta1','ta1count',100);"
></textarea>
<br/>
<input id="ta1count" readonly type="text" size="30"/>
</form>
<script type="text/javascript">
textCounter('ta1','ta1count',100);
</script>
This script works well outside of a Facebook frame, but I don't understand the limitations of FBJS and what I'd need to change to make this script work. Has anyone had success implementing a similar feature?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您发布的代码片段不起作用。
这是一个确实有效的版本(经过测试)
在您的示例中,您试图从字符串中获取值。
textareaid.value
textareaid 不是此范围内的节点。
You code snippet you posted doesn't work.
here is a version that does work (is tested)
In you example you are trying to get a value from a string.
textareaid.value
textareaid isn't a node in this scope.