Home > Web Front-end > JS Tutorial > Detailed explanation of how javascript operates server control code examples

Detailed explanation of how javascript operates server control code examples

伊谢尔伦
Release: 2017-07-24 10:24:31
Original
1501 people have browsed it

js select server control select and dropdownlist

1. js operation server control select

<select id="selectID" onchange="return showMessage()">
     <option value="0">==请选择==</option>
     <option value="1">是</option>
     <option value="2">否</option>
</select>
Copy after login
<script type="text/javascript" language="javascript">
  function showMessage() {
      if (document.getElementById("selectID").options[document.getElementById("selectID").selectedIndex].value == 1) {
   alert("你好,你选择了第 1 个");
   document.getElementById("txtContractName").setAttribute("enable",false);
      }
      else if (document.getElementById("selectID").options[document.getElementById("selectID").selectedIndex].value == 2) {
   alert("你好,你选择了第 2 个");
      }
  }
</script>
Copy after login
//js操作服务器控件dropdownlist
<asp:DropDownList ID="ddlFolder" runat="server" SkinID="ddlSkin" AutoPostBack="false" OnSelectedIndexChanged="ddlFolder_SelectedIndexChanged">    
        <asp:ListItem Value="0">选项0</asp:ListItem>   
   <asp:ListItem Value="1">选项1</asp:ListItem>  
</asp:DropDownList>    
<asp:DropDownList ID="ddlFolder" runat="server" SkinID="ddlSkin" AutoPostBack="false" OnSelectedIndexChanged="ddlFolder_SelectedIndexChanged"> 
  <asp:ListItem Value="0">选项0</asp:ListItem>
  <asp:ListItem Value="1">选项1</asp:ListItem> 
</asp:DropDownList>
Copy after login

JS code:

document.getElementById("ddlFolder").value="0";//0为你要选中的项的value
Copy after login

2 . Select an item based on the Text value setting

var DropDownListCurrencyNew =  document.getElementById("ddlFolder");
for(i = 0; i < DropDownListCurrencyNew.options.length; i++)
{
          if(DropDownListCurrencyNew.options[i].text == "选项0")    
           {
               DropDownListCurrencyNew.options[i].selected = true; 
          }
}
Copy after login

js reads the value and text of the DropDownList selected item

Value:

var selValue = document.getElementById("DropDownList1").options[document.getElementById("DropDownList1").selectedIndex].value;
Copy after login

Text:

var selText = document.getElementById("DropDownList1").options[document.getElementById("DropDownList1").selectedIndex].text;
Copy after login


The above is the detailed content of Detailed explanation of how javascript operates server control code examples. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template