JavaScript and ASP.NET

xiaoxiao2021-03-06  40

Due to the needs of the project, it has a certain understanding of JS development in recent time. In the development of ASP.NET, often requires JS scripts to add some client control, such as restricting input characters, date controls, and more. Generally, such control is substantially better in the client, no need to return to the server. Summarize some JS skills used in the recent development, provide for everyone

1. How JS scripts access the value of the server control

There is a TextBox control on the interface, ID is Name, and the value of Name is taken as follows in JS.

Var myvalue = document.all ('name'). Value;

2, how to take the value of variables in JS

There is no better way, I usually use the way to put a hidden control HTMLINPUTHIDEN, and then set to run in the server control, which can access the control in the JS script and the ASP.NET code. value

JS assigns the server control:

VAR bt = document.all ('name'). Value;

bt.value = 'name';

Use Name.Value in ASP.NET to access.

3, how to traverse all TextBox elements on the interface

Var INPUTLIST = Document.body.getElementsBytagname ("Input");

For (var i = 0; i

{

IF (InputList [i] .disabled == false && (InputList [i] .type == 'text' || InputList [i] .type == 'password'))

{

InputList [i] .value = ""

}

}

4, let DropDownList to select the specified item

Select DROPDOWNLIST to be "I have to choose"

VAR HANDL = Document.all ('List1');

Var my_value = 'I have to choose';

For (var index = 0; index

{

IF (Handle.Options [index] .text == my_value)

{

Handle.selectedIndex = Index;

}

}

转载请注明原文地址:https://www.9cbs.com/read-56620.html

New Post(0)