简体   繁体   English

这个脚本到底在做什么? 试图了解JavaScript

[英]what exactly is this script doing? trying to understand 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>     

is this script checking if editortextbox1 is empty or not ? 这个脚本是否检查editortextbox1是否为空? 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. 另外,如果我确实要检查editortextbox1是否为空,则应如何修改此脚本。 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). 就像我有2-3个文本框(实际上是RadEditor)。 I want to check for null values in all the editors. 我想检查所有编辑器中的空值。 How should I modify this script?? 我应该如何修改此脚本?

It's ensuring that the editortextbox1 field has less than 15 characters, and more then than 100...meaning it can never be valid. 它确保editortextbox1领域拥有少于 15个字符, 多则超过100 ...这意味着它永远是有效的。 It seems like it should be: 似乎应该是:

args.IsValid = editorText.length <= limitNum && editorText.length >= 15;

to be a valid check. 是有效的支票。

The script defines two variables and a function. 该脚本定义了两个变量和一个函数。 It does not check anything. 它不检查任何内容。

When the function is executed, it sets args.IsValid to false . 执行该函数时,它将args.IsValid设置为false This is because editorText.length > 100 && editorText.length < 15 is always false . 这是因为editorText.length > 100 && editorText.length < 15始终为false

currently args.IsValid will be always false: 当前args.IsValid始终为false:

editorText.length > limitNum && editorText.length < 15;

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. 没有什么可以大于100且小于15。无论如何,我相信此函数当前旨在返回某些Textbox长度的有效性(可能要检查最小和最大长度),无论如何脚本本身不执行任何操作,但是调用此函数的代码可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM