Recommended: ASP program realizes the pagination function of saving parameter values The following is the referenced content: <%''' '' Call example'Dim int_RPP, int_Start, int_showNumberLi
Why learn scripting language? What is the relationship between ASP and scripting language?
First, let’s talk about what ASP is precious. ASP is the short name for Microsoft Active Server Pages, a server-side scripting environment that can be used to create interactive web pages and build powerful web applications. It can be shown that ASP is a server-side scripting environment, so we understand why ASP needs IIS support, because IIS is a commonly used web server; then we understand why we need to learn scripting languages, because ASP provides a scripting environment.
Again, ASP is just an environment, not a language. If you really want to say that ASP is a network programming language in a visual way, it is also a powerful hybrid language with built-in objects and components provided by the html script asp.
Therefore, it is very important to learn some scripts! In fact, whether you are learning script languages or other languages, I think the first thing you need to understand is the various characteristics covered by the language, including: data types, events, methods, objects, attributes, grammar, etc. Of course, these are all empty talk. Just like a computer language class in a university class, what you do is purely research is a bit boring. It is better to be more practical. A program that can solve problems is a good program (certify that a cat that can catch a mouse is a classic holy saying of a good cat, haha)
Of course, you still need to study language. For example, if you write a program that finds absolute values, you can actually do it with an abs() function. For example, you know how to use vb scripts, but replacing the same program with Java scripts will make an error. Their data types are different and the statement syntax is also different. Just like Chinese and foreign languages, you need to know the pronunciation symbols (data type), how to pronounce (method), how to say it in one sentence (grammar)... Haha, it makes you feel a little uncomfortable. OK! Direct. What you need to pay attention to in the future is the functions and syntax of the language. Of course, it is not for you to read it all. Follow the encounters in the tutorial to master the other ones. After finishing the tutorial, it is almost over. Haha, you have to believe me.
There are currently two main scripting languages: VbScript and JavaScript. Because VbScript is the default server script for IIS, what we are talking about is basically ASP based on VbScript as scripts. Of course, it is not ruled out that JavaScript is sometimes used.
Let's give a very simple example:
| The following is the quoted content: <script language=vbscript> <!-- sub button1_onclick msgbox (Welcome to vbscript!) end sub --> </script> <script language=javascript> <!-- function b213() { alert (Welcome to javascript!) } --> </script> <form> <input type=button name=button1 value=vbs><br> <input type=button name=button2 value=js onclick=b213()> </form> |
Sub in vbscript is an event process. The process name contains two parts: part is the button name, namely Button1 (gets from the NAME attribute in the <INPUT> tag); the other part is the event name, namely OnClick. The two parts are connected by an underscore (_). When clicking the button, Internet Explorer searches and runs the corresponding event process, namely Button1_OnClick, and MsgBox is a function. For its more specific parameters, you can take a good look.
When it comes to a moment of excitement, everyone may see a crazy and disgusting dialog box group on the Internet. What is the principle? Please see:
| The following is the quoted content: <script language=vbscript> msgbox you know you will click sure. . . . . . . If you don’t click on msgbox, you should click on it. . . . . . . . There is no way to msgbox, right? . . . . . . . . . ? The msgbox web page won’t be opened. . . . . . msgbox is a trick to harm people. . . . . . . . . msgbox really wants to beat the webmaster. . . . . . . . . </script> |
In fact, when the webmaster uses these to play with others, he plays with himself first: because he thinks all of them:)
Haha, I don’t mean to hurt everyone, just to learn.
The principle of opening and closing pop-up dialog box
| The following is the quoted content: <script language=vbscript> <!-- sub window_onload() msgboxwelcome you! end sub sub window_onunload() msgboxsee you late! end sub --> </script> |
The opening page shows welcome you!, and the closing page shows see you late!
The above is just a display dialog box msgbox, and of course the writing dialog box inputbox will also be checked by the way.
| The following is the quoted content: <script language=vbscript> <!-- dim strname strname=inputbox(enter your name please:,enter your name,cnbruce) document.write(strname&,welcome you!<p>) --> </script> |
If you want to close the parameters of the inputbox, go and have a look.
Let’s take a look at a few practical functions:
len(): Returns the string length or the byte length of the variable
lef(): Intercept the first part of a string
right(): Intercept the last part of a string
| The following is the quoted content: <script language=vbs> text=1234567890abcdefgh i=10 lentext=len(text) lefttext=left(text,i) righttext=right(text,i) alert (text length is: &lentext) alert (The text left is taken &i& to get: &lefttext) alert (The text is taken right and gets: &righttext) </script> |
Based on these, the situations that you often see after long articles are as follows:
The following is the quoted content: <script language=vbs> text=123 4567 8fds90 abcde fghxcfv i=10 if len(text)>i then 'If the text length is greater than the given value text=left(text,i) 'Then extracts the string of i bits in the previous section alert (text&...) else alert (text) end if </script> |
There is another more important function replace()
Search in a string, instead of the specified string
replace(strtobesearched,strsearchfor,strreplacewith)
strtobesearched is a string; strsearchfor is the substring being looked up; strreplacewith is the substring used to replace.
The following is a very useful text conversion program
| The following is the quoted content: <script language=vbs> text=Hello, welcome text=replace(text, hello, nihao) text=replace(text,welcome,ying) alert (text) </script> |
When sending EMAIL, multiple addresses are added, and the middle is separated by the number. How to decompose multiple EMAIL addresses received? Use the Split function: The Split function returns an array from a string.
| The following is the quoted content: <script language=vbs> [email protected];[email protected];[email protected] MyArray = Split(CuoXIn, ;) a=MyArray(0) b=MyArray(1) c=MyArray(2) alert(a) alert(b) alert(c) </script> |
These are more realistic and fun, and learning is good while playing :) But after all, we need to program. Speaking of writing programs, I know that the program structure can be divided into:
1. Sequence structure: It is the most common program that executes from top to bottom and from left to right
2. Select the structure: give you two conditions, either this way (if ... then), or that way (else), you can choose:)
3. Loop structure: gives you the most space to play, and perform activities (loops) if it does not exceed this range, otherwise it will automatically exit (loops out).
No matter how complex the program is, it is nothing more than a comprehensive nesting application of these three structures, right?
There is not much to say about the sequence structure, because the program execution is basically in this direction.
Let’s take a look at the selection structure. Of course, the selection structure can also be nested.
| The following is the quoted content: <body> hello, <script language=vbscript> <!-- dim thishour thishour=hour(time) if thishour<=12 then document.bgcolor=red document.fgcolor=black document.write(Good morning!) else if thishour<=18 then document.bgcolor=blue document.fgcolor=white document.write(Good afternoon!) else document.bgcolor=green document.fgcolor=yellow document.write(good evening!) end if end if --> </script> The purpose of this page is to display different colors and welcome messages according to different times. </body> |
The above program is very simple. As long as you can understand English, you will understand the program (this is how I understand it:)
First submit the current hour: hour(time);
Then compare it with 12 to judge that if <=12, it must be in the morning, otherwise it will be in the afternoon and evening;
Otherwise, the conditions will continue to be judged. If the time is <=18, it will definitely be afternoon;
Finally, needless to say, the blind man knows it's evening :)
The document.bgcolor in the previous program is the background color of the document, document.fgcolor is the foreground color of the document (text color). The next program changes the background color dynamically.
| The following is the quoted content: <script language=vbscript> <!-- sub setbgcolor(bcolor) document.bgcolor=bcolor end sub --> </script> <form> <input type=radio name=color onclick=setbgcolor(red)>red<br> <input type=radio name=color onclick=setbgcolor(green)>green<br> <input type=radio name=color onclick=setbgcolor(blue)>blue<br> <input type=radio name=color onclick=setbgcolor(yellow)>yellow<br> <input type=radio name=color onclick=setbgcolor(gray)>gray<br> </form> |
Nesting a conditional selection structure and then showing a form detection program
| The following is the quoted content: <html><head><title>abc</title> <script language=vbscript> <!-- sub btnsubmit_onclick if form1.name.value<> then if form1.addr.value<> then if form1.email.value<> then if instr(form1.email.value,@)<>0 and instr(form1.email.value,.)<>0 then form1.submit else alertemail error! end if else alert enter your email! form1.elements(email).focus end if else alert enter your address! form1.elements(addr).focus end if else msgbox enter your name please! form1.elements(name).focus end if end sub --> </script> </head> <body> <form name=form1 method=post action=bug.html> your name:<input type=text name=name><br> your addr:<input type=text name=addr><br> your email:<input type=text name=email><br> <input type=button name=btnsubmit value=submit> </form> </body> </html> |
The program is given, but it seems difficult to understand. Sometimes the program execution time is also more important, so the program code must be simplified.
As the saying goes: it is easy to write programs, but it is difficult to write classic programs. The above programs can also be used to change their thinking style. Use javascript instead (Note: I learned programming ideas, don’t worry too much about script types)
| The following is the quoted content: <html> <head> <title>abc</title> <script language=javascript> <!-- function form1_onsubmit() { if (document.form1.name.value==) { alert (Please set your login name.) document.form1.name.focus() return false } else if(document.form1.addr.value==) { alert (Please fill in your address.) document.form1.addr.focus() return false } else if(document.form1.email.value==) { alert (Please fill in your E-Mail address.) document.form1.email.focus() return false } } --> </script> </head> <body> <form name=form1 onsubmit=return form1_onsubmit()> your name:<input type=text name=name><br> your addr:<input type=text name=addr><br> your email:<input type=text name=email><br> <input type=submit name=submit value=submit> </form> </body> </html> |
Finally, let’s take a look at the loop structure: 1 to 500 are not written one by one.
| The following is the quoted content: <script language=vbs> for i= 1 to 500 document.write(i&<br>) next </script> |
Of course, loops can not only be used for, but also do while...loop, etc.
Anyway, the program is a substitute for us to do many repetitive and single boring things - as long as you make reasonable use of the program.
There should be some achievements. Learning language and programming means learning grammar and semantics, and learning programming architecture ideas.
Of course, this requires you to have a solid foundation in this language. What is the basis? Do you know which functions? Do you know how to use programs to judge even numbers (including operations)? Do you know how to do form testing? Do you know which three program architectures?
Haha, if you understand the above programs thoroughly, it is best to read the script reference manual more, and you can start ASP with me.
repair:
The Function process is similar to the Sub process, but the Function process can return a value.
Function procedures can also use constants, variables, or expressions passed by the calling procedures as parameters. If the Function procedure has no parameters, the Function statement must contain parentheses.
The Function procedure returns a value through the function name, which is assigned to the function name in the statement of the procedure. The data type of the function return value is always Variant.
Share: Prevention of Cookies spoofing vulnerabilities (vbs js implementation) 1. Attack principle Cookies spoofing mainly uses the unsafe practice of storing user login information in cookies on the current network. The attack method is relatively difficult compared to vulnerabilities such as SQL injection vulnerabilities&rdquo