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

发布于 2024-10-08 09:51:55 字数 839 浏览 0 评论 0原文

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半岛未凉 2024-10-15 09:51:55

它确保 editortextbox1 字段少于 15 个字符,并且多于 100 个字符......这意味着它永远不会有效。看起来它应该是:

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

成为一张有效的支票。

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:

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

to be a valid check.

苯莒 2024-10-15 09:51:55

目前 args.IsValid 将始终为 false:

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

任何值都不能大于 100 且小于 15。
无论如何,我相信这个函数当前的目的是返回某些文本框的长度的有效性(可能是为了检查最小和最大长度),无论如何脚本本身不执行任何操作,但是调用这个函数的代码会执行任何操作。

currently args.IsValid will be always 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.

夏末的微笑 2024-10-15 09:51:55

该脚本定义了两个变量和一个函数。它不检查任何东西。

执行该函数时,它将 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 to false. This is because editorText.length > 100 && editorText.length < 15 is always false.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文