English 中文(简体)
Java字错误方框
原标题:Javascript error box

Hi guys I have this script here, which counts the characters and lines, now currently though it still allows lines and characters to go into minus, but I would like it to also put up a warning box so it stops the user from being able to put in more text, could you help me out?

javascript:

function textCounter(theField,theCharCounter,theLineCounter,maxChars,maxLines,maxPerLine) {
    var strTemp = "";
    var strLineCounter = 0;
    var strCharCounter = 0;

    for (var i = 0; i < theField.value.length; i++)
    {
        var strChar = theField.value.substring(i, i + 1);
        if (strChar ==  
 )
        {
            strTemp += strChar;
            strCharCounter = 1;
            strLineCounter += 1;
        }
        else if (strCharCounter == maxPerLine)
        {
            strTemp +=  
  + strChar;
            strCharCounter = 1;
            strLineCounter += 1;
        }
        else
        {
            strTemp += strChar;
            strCharCounter ++;
        }
    }

    theCharCounter.value = maxChars - strTemp.length;
    theLineCounter.value = maxLines - strLineCounter;
}

并用于编码:

<textarea name="comment" cols="50" rows="10" wrap="VIRTUAL" onKeyUp="textCounter(theForm.comment,theForm.remChars,remLines,900,30,50);"></textarea>
<br><input name=remChars type=text value="900" size=3 maxlength=3 readonly> characters left
<br><input name=remLines type=text value="30" size=3 maxlength=3 readonly> lines left<br>

汇报工作

最佳回答

1 - 在职能结束时添加检查:

var check = strTemp.length <= maxChars && strLineCounter <= maxLines;
if (!check) alert("Error message here!");

2 - 附上实地文本,因此只包含所需果园:

theField.value = theField.value.sbustring(0, maxChars - 1);

3 - 恢复职能:

return check ;

4 - 改变对以下事项具有约束力的活动:

onKeyUp="return textCounter(theForm.comment,theForm...
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签