好的,所以除了我的 toLowerCase 之外,我得到了所有这些工作。它不起作用,因此如果区分大小写,它将不会拆分。我正在使用下拉框来选择我的分隔符。
已经发布了js代码来帮助大家指出问题。我仔细检查了它,但我认为它需要一双新的眼睛。
window.onload = function() {
document.getElementById("change").onclick = function () {
var paragraph = document.getElementById('box').value;
var x = document.getElementById("changeCase");
var getInfo = document.getElementById('ParaWrite');
var LowerCase = " ";
var LowerCase2 = " ";
var splitAT = " ";
var options = document.getElementById("split").value;
alert("above the for loop");
if (x.checked === true)
{
LowerCase = paragraph.toLowerCase();
}
else
{
LowerCase = paragraph;
}
for (var i = 0; i < document.form1.split.options.length; i++)
{
if (document.form1.split.options[i].selected === true)
{
splitAT = paragraph.split(options);
alert("splitAT[" + i + "]=" + splitAT[i]);
}
}
console.log(document.form1.split.options);
document.write(splitAT +" " +splitAT.length);
}
HTML 代码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Paragraph</title>
<link rel="stylesheet" href="normalize.css">
<link rel="stylesheet" href="Textbox.css">
</head>
<body>
<h1>Please enter some Text</h1>
<form name="form1" id="form1">
<textarea type="text" id="box" value=""/></textarea>
<label for="write">Case Sensitive checkbox</label>
<input type='checkbox' name='write' id='changeCase' value='Check'/><br>
<input type='button' value="Count" id="change"/>
<select name="split" id="split">
<option value="like">like</option>
<option value="monkey">monkey</option>
<option value="I">I</option>
<option value=".">.</option>
<option value=",">,</option>
<option value="?">?</option>
<option value=" ">[Space]</option>
</select>
</form>
<div id="ParaWrite">
</div>
<script type="text/javascript" src="die.js"></script>
</body>
</html>