Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何限制textarea并从extarea移动到另一个extarea_Javascript_Css_Forms_Textarea_Wysiwyg - Fatal编程技术网

Javascript 如何限制textarea并从extarea移动到另一个extarea

Javascript 如何限制textarea并从extarea移动到另一个extarea,javascript,css,forms,textarea,wysiwyg,Javascript,Css,Forms,Textarea,Wysiwyg,我正在构建一个“所见即所得”,我有一个小问题: 我有两个文本区域 我想限制第一个文本区域的写作量,当我完成第一个文本区域的写作后,自动继续第二个文本区域的写作 就像“单词”中一样: 我正在使用execCommand,所以我不希望它依赖于字体大小/空格等 您可以在文本区域上使用maxlength属性: <textarea maxlength="number"> 编辑: 您可以执行类似的操作来包括输入字符 <textarea id="mytext" rows="4" col

我正在构建一个“所见即所得”,我有一个小问题:

我有两个文本区域

我想限制第一个文本区域的写作量,当我完成第一个文本区域的写作后,自动继续第二个文本区域的写作

就像“单词”中一样:


我正在使用execCommand,所以我不希望它依赖于字体大小/空格等

您可以在文本区域上使用maxlength属性:

<textarea maxlength="number">

编辑:

您可以执行类似的操作来包括输入字符

<textarea id="mytext" rows="4" cols="50" onkeyup="LimitCharacters(this);" >
</textarea>
<textarea id="mytext2" rows="4" cols="50">
</textarea>
<script>
function LimitCharacters(textArea) {
    var chars = textArea.value.length;
    if (chars > 10) {
        var words = textArea.value.split(" ");
        var lastWord = words.pop();
        textArea.value = words.join(" ");
        document.getElementById("mytext2").focus();
        document.getElementById("mytext2").value = lastWord;
    }
}
</script>

函数限制字符(文本区域){
var chars=textArea.value.length;
如果(字符数>10){
var words=textArea.value.split(“”);
var lastWord=words.pop();
textArea.value=words.join(“”);
document.getElementById(“mytext2”).focus();
document.getElementById(“mytext2”).value=lastWord;
}
}

应该是这样的。 检查每次在文本区域中键入的行数。 如果行数大于最大行数,请将焦点设置在其他文本区域

我还没试过

String.prototype.lines = function() { return this.split(/\r*\n/); }
String.prototype.lineCount = function() { return this.lines().length; }

var maxLineCount = ...;

$('#textarea1').bind('input propertychange', function(e)
{
    if((this).val().lineCount > x)
    {
        e.preventDefault();
        $('#textarea2').focus();
    }
});
编辑:另一种方法是使用插件扩展文本区域,同时在其中键入文本。并设置最大高度。达到最大高度后,请将注意力集中在其他文本区域

尝试以下操作:

<textarea id="firstTextArea" maxlength="100" />
<textarea id="secondTextArea" />

使用此脚本:

<script>
    $("#firstTextArea").on("keypress", function(){
        if($("#firstTextArea").length == 100){
            $("#secondTextArea").focus();
        }
    }
<script>

$(“#firstTextArea”)。在(“按键”,函数()上{
如果($(“#firstTextArea”)。长度==100){
$(“#secondTextArea”).focus();
}
}
我已经对它进行了测试,工作正常。
下面是脚本
功能自动选项卡(当前,至){
if(current.getAttribute&&
current.value.length==current.getAttribute(“maxlength”)){
to.focus()
}
}
这是HTML…请不要错过名为attr的表单标签。

差不多。重点必须放在SecondTextArea上。它不起作用。而且我也希望像在word中一样,如果我在整页中插入单词,页面上的最后一个单词应该转到下一页。你是否使用jquery?我的意思是,在这个片段中什么不起作用?它永远不会到达这个循环:if($(“#firstTextArea”)。长度==100)即使它真的起作用了,我也不会有word中那样的效果:当我在一整页中插入文本时,页面中的最后一个单词应该转到下一个文本区域。这不一定是“焦点”不起作用。而且我也希望像word中一样,如果我在一整页中插入单词,页面上的最后一个单词应该转到下一页。它几乎是在我之前,就像在Word中一样,如果我在整页中插入单词,页面上的最后一个单词应该会转到下一页好的,我更新了答案和小提琴。这就是你要找的吗?谢谢,它几乎就在那里,尽管它仍然有bug。最后一个单词不一定是我写的最后一个单词,而是文本区域中的最后一个单词。还有,随着我写的越来越多,更多的单词应该转移到下一个文本区域。你的代码是什么?你希望人们为你提供完整的解决方案吗?这很好,还不是我想要的。你仍然可以在旁边看到滚动条(例如,如果你连续写一封信)在其中一个文本区域中完成书写后,您不能添加字符,您应该能够添加字符,这样,文本区域中的最后一个单词将被推送到下一个文本区域。
I have tested it and working fine. 
below is script
<script>
function autotab(current,to){
    if (current.getAttribute && 
      current.value.length==current.getAttribute("maxlength")) {
        to.focus() 
        }
}
</script>

here is HTML ... please dont miss form tag with name attr.
<form name="note">
<textarea name="phone0" size=200 onKeyup="autotab(this, document.note.phone1)" maxlength=10></textarea>
<textarea name="phone1" size=200 onKeyup="autotab(this, document.note.phone2)" maxlength=10></textarea>
<textarea name="phone2" size=200 maxlength=10></textarea>
</form>