我遇到了一些问题,我的JavaScript代码没有计算输入的字符数,我很困惑。有什么想法吗?
HTML:
<script src="https://ajaxgoogleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<label for="studentName">Student name:</label>
<textarea id="studentName" cols="40" rows"3"></textarea><br>
<p id="stringLength">0</p>
JavaScript:
var $textareaElement = $("#studentName");
function textSize(event) {
$("#stringLength").text($textareaElement.val().length);
}
/* Your solution goes here */
$(document).ready(function () {
$("#studentName").focus(function () {
$("#stringLength").html($(this).val().length);
});
});
测试:
测试"Hi“中的字符数显示Your和expected不同。请看下面的高亮部分。
是你的
0
期望的
2
测试"How are you?“中的字符数。显示了您的结果与预期的不同。请看下面的高亮部分。
是你的
0
期望的
12
测试"Good Game“中的角色数量显示您和预期的不同。请看下面的高亮部分。
是你的
0
期望的
9个
https://stackoverflow.com/questions/55367020
复制相似问题