When working on BS architecture projects, we often encounter the need to use js to call the Asp.net server-side control value.
The value of most controls can be obtained by calling its value attribute in JS, but there are exceptions.
Label controls are commonly used. The value cannot be obtained through the value attribute in Js.
Example obtained by label control JS, VAR text = Document. getelementbyid ('label1'). innertext;
If var text = Document. getelementbyid ('label1'). value; then text is undefined.
The textbox Value
VaR text = Document. getelementbyid ('textbox 1'). value;
For radiobuttonlist and dropdownlist, their acquisition methods are quite different! This is mainly because they generate different HTML elements.
The value of dropdownlist is relatively simple:
VaR ddlvalue = Document. getelementbyid ('ctl00 _ contentplaceholder3_ddlfolws '). value;
However, obtaining the value of radiobuttonlist is troublesome:
VaR value = "";
var result = document. getelementsbyname ('ctl00 $ contentplaceholder3 $ rblresult');
for (VAR I = 0; I If (result. item (I ). checked) {
value = result. item (I ). value;
}< BR style = "line-Height: 10px;" >}
If no value is selected for the radiobuttonlist control, the value is blank!
====== Substring usage (string truncation) ======
function substringdemo () {
var SS; // declare a variable.
var S = "The rain in Spain falls mainly in the plain .. ";
SS = S. substring (12, 17); // obtain the substring.
return (SS); // returns a substring.
}
From: http://kb.cnblogs.com/a/2288883/