<!DOCTYPE HTML>
<html>
<head>
<title> Javascript - stuff </title>
<script type="text/javascript">
<!--
function GetCountsAll(Wordcount, Sentancecount, Clausecount, Charactercount)
{
var TextString = document.getElementById("Text").innerHTML;
var Wordcount = 0;
var Sentancecount = 0;
var Clausecount = 0;
var Charactercount = 0;
// For loop that runs through all characters incrementing the variable(s) value each iteration
for (i=0; i < TextString.length; i++);
if (TextString.charAt(i) == " " = true)
Wordcount++;
return Wordcount;
if (TextString.charAt(i) = "." = true)
Sentancecount++;
Clausecount++;
return Sentancecount;
if (TextString.charAt(i) = ";" = true)
Clausecount++;
return Clausecount;
}
-->
</script>
</head>
<body>
<div id="Text">
It is important to remember that XHTML is a markup language; it is not a programming language. The language only describes the placement and visual appearance of elements arranged on a page; it does not permit users to manipulate these elements to change their placement or appearance, or to perform any "processing" on the text or graphics to change their content in response to user needs. For many Web pages this lack of processing capability is not a great drawback; the pages are simply displays of static, unchanging, information for which no manipulation by the user is required. Still, there are cases where the ability to respond to user actions and the availability of processing methods can be a great asset. This is where JavaScript enters the picture.
</div>
<input type = "button" value = "Get Counts" class = "btnstyle" onclick = "GetCountsAll()"/>
<br/>
<span id= "Charactercount"> </span> Characters <br/>
<span id= "Wordcount"> </span> Words <br/>
<span id= "Sentancecount"> </span> Sentences <br/>
<span id= "ClauseCount"> </span> Clauses <br/>
</body>
</html>
我是一名学生,仍在学习JavaScript,所以请原谅任何可怕的错误。该脚本旨在计算该段落中的字符,单词,句子和条款的数量。简单地说,就是不工作。我已经尝试了很多事情来让它为我工作,并且得到了很多不同的错误,但是不管我无法得到这个工作。请帮忙! (顺便说一句,我知道我拼写错误的句子)用于统计字符/单词不工作的功能
为什么在for语句后面有';'?而且你不计算单词 - 你正在计算字符串中的空格数量,这可能不是实际的单词数量。我对代码进行了重新缩进,以使问题更加混杂 – nhahtdh
此代码是由您编写的吗? – zerkms
我知道空间可能不是==这个词确切地说,这是可以接受的。 – user1742729