这个脚本到底在做什么?试图理解 JavaScript
<script type="text/javascript">
var limitNum = 100;
var message = 'You are not able to type more than ' + limitNum + ' symbols!';
function checkLength(validator, args)
{
var editor = <%=editortextbox1.ClientID%>; // get a reference to RadEditor
var editorText = editor.GetText(true); //get the HTML content of the control
args.IsValid = editorText.length > limitNum && editorText.length < 15;
}
</script>
该脚本是否检查 editortextbox1 是否为空?如果不是,它在做什么?另外,如果我确实想检查 editortextbox1 是否为空,我应该如何修改这个脚本。哦,如果我希望这个脚本针对我页面上的所有文本框运行,我需要做什么更改?就像我有 2-3 个文本框(实际上是 RadEditors)。我想检查所有编辑器中的空值。我应该如何修改这个脚本?
<script type="text/javascript">
var limitNum = 100;
var message = 'You are not able to type more than ' + limitNum + ' symbols!';
function checkLength(validator, args)
{
var editor = <%=editortextbox1.ClientID%>; // get a reference to RadEditor
var editorText = editor.GetText(true); //get the HTML content of the control
args.IsValid = editorText.length > limitNum && editorText.length < 15;
}
</script>
is this script checking if editortextbox1 is empty or not ? if not, what is it doing? Also, if I do want to check that editortextbox1 is empty or not, how should I modify this script. Oh and what if I want this script to run for ALL the Textboxes on my page, what change do i need to make then?? Like I have 2-3 Text boxes(which are actually RadEditors). I want to check for null values in all the editors. How should I modify this script??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它确保
editortextbox1
字段少于 15 个字符,并且多于 100 个字符......这意味着它永远不会有效。看起来它应该是:成为一张有效的支票。
It's ensuring that the
editortextbox1
field has less than 15 characters, and more then than 100...meaning it can never be valid. It seems like it should be:to be a valid check.
目前 args.IsValid 将始终为 false:
任何值都不能大于 100 且小于 15。
无论如何,我相信这个函数当前的目的是返回某些文本框的长度的有效性(可能是为了检查最小和最大长度),无论如何脚本本身不执行任何操作,但是调用这个函数的代码会执行任何操作。
currently args.IsValid will be always false:
nothing can be greater than 100 and less than 15.
Anyway i believe that this function was currently meant to return the validity of the length of certain Textbox (probably to check a minimum and maximum length), anyways the script itself doesn't do anything, but the code that calls this function does.
该脚本定义了两个变量和一个函数。它不检查任何东西。
执行该函数时,它将
args.IsValid
设置为false
。这是因为editorText.length >第100章editorText.length < 15
始终为false
。The script defines two variables and a function. It does not check anything.
When the function is executed, it sets
args.IsValid
tofalse
. This is becauseeditorText.length > 100 && editorText.length < 15
is alwaysfalse
.