zoukankan      html  css  js  c++  java
  • ajax/应用1

       //init_xmlhttp函数会根据不同的浏览器初始化xmlhttp对象 
             function init_xmlhttp()
             
    {
                   
    var A=null
                   
    try 
                   

                        A
    =new ActiveXObject("Msxml2.XMLHTTP"); //IE 
                   }
     
                   
    catch(e) 
                   

                       
    try 
                       

                             A
    =new ActiveXObject("Microsoft.XMLHTTP"); //非IE
                       }
     
                       
    catch(oc) 
                       

                             A
    =null 
                       }
     
                   }

                   
                   
    if ( !&& typeof XMLHttpRequest != "undefined" ) 
                   

                        A
    =new XMLHttpRequest() 
                   }
     
                  
    return A 
             }


          
            
    function Go(obj) 
            

                
                  
    var var1 = document.form1.ddl_1[document.form1.ddl_1.selectedIndex].value;
                  
    if((var1 == "7")||(var1 == "5")) //5核销人 7 支付方式
                  {
                        
    //得到选择框的下拉列表的value 
                        var svalue = obj.value;   
    //                    alert(svalue);return false;
                        //定义要处理数据的页面 
                        var weburl = "select_data_ysfhxcx.aspx?list_item_value="+svalue;    
                        
    //初始化个xmlhttp对象 
                        var xmlhttp = init_xmlhttp(); 
                        
                        
    //去weburl获取数据,第一个参数最好为get,第三个参数最好为true 
                        xmlhttp.open("get",weburl,true); 
    //                    alert("a"); return false;//执行了
                        xmlhttp.onreadystatechange=function() 
                        
    {
    //                        alert(xmlhttp.readyState); return false;//这时接到的值为1,不知是什么意思,可能表示开始执行,在select_data_ysdzd.aspx中就能断到断点
                            if(xmlhttp.readyState == 4)//4代表成功返回数据 
                            {
                                
    var result = xmlhttp.responseText;//得到服务器返回的数据
                                document.getElementById("txt_of_pnl1").style.display = "none";
                                document.getElementById(
    "ddl_of_pnl1").style.display="";
                                document.getElementById(
    "ddl_of_pnl1").length = 0;                                           
                                document.getElementById(
    "ddl_of_pnl1").options.add(new Option(" "," ")); 
                                
    if(result != "")//如果返回的数据不是空 
                                {
    //                               alert(result);return false;
                                     var allArray = result.split(",");
                                     
    //循环这个数组,注意是从1开始,因为收到的字符串第一个字符是,号,所以分割后第一个数组为空 
                                     for(var i=1;i<allArray.length;i++
                                     
    {
                                        
    var thisArray = allArray[i].split("|");
                                        document.getElementById(
    "ddl_of_pnl1").options.add(new Option(thisArray[0].toString(),thisArray[1].toString())); 
                                     }

                                }

                                
    else
                                
    {
                                    document.getElementById(
    "ddl_of_pnl1").length = 0
                                }

                            }

                            
                        }

                         xmlhttp.send(
    null); //没有这句,根本进不到select_data_ysdzd.aspx页面!!!!!     
                  }
    //if((var1 == "7")||(var1 == "5"))   End
                  else
                  
    {
                       document.getElementById(
    "txt_of_pnl1").style.display = "";
                       
                       document.getElementById(
    "ddl_of_pnl1").style.display = "none";
                  }

            }
    CS:
      ddl_1.Attributes.Add("onchange""Go(this)");//最左边的按钮"各种检索条件"
            this.ddl_of_pnl1.Attributes.Add("onchange""javascript:document.form1.hid_ddl_right.value=this.value;");//右边panel中的DDL


    HTML:
     <td>
            
    <asp:DropDownList ID="ddl_1" runat="server" Width="140px">
                
    <asp:ListItem Text="" Value="0"></asp:ListItem>
                
    <asp:ListItem Text="编号" Value="1"></asp:ListItem>            
                
    <asp:ListItem Text="单号" Value="2"></asp:ListItem>            
                
    <asp:ListItem Text="凭证号" Value="3"></asp:ListItem>
                
    <asp:ListItem Text="支票号" Value="4"></asp:ListItem>            
                
    <asp:ListItem Text="核销人" Value="5"></asp:ListItem>
                
    <asp:ListItem Text="涉帐单位" Value="6"></asp:ListItem>
                
    <asp:ListItem Text="支付方式" Value="7"></asp:ListItem>
            
    </asp:DropDownList>
        
    </td>
        
    <td>        
            
    <asp:Panel ID="pnl1" runat="server" Width="100px" >
                
    <asp:TextBox ID="txt_of_pnl1" runat="server" Width="140px" CssClass="input_text"></asp:TextBox>
                
    <asp:DropDownList ID="ddl_of_pnl1" style="display:none;" runat="server"   Width="140px">
                                    
    </asp:DropDownList>
            
    </asp:Panel>
        
    </td>
  • 相关阅读:
    Intellij IDEA创建Maven Web项目<转>
    Spring事件监听Demo
    maven打包源码<转>
    枚举类转成json
    Java多线程编程中Future模式的详解<转>
    细数JDK里的设计模式<转>
    设计模式-观察者模式(下)<转>
    Sqlserver自定义函数Function
    sqlSQL2008如何创建定时作业
    JSON 序列化和反序列化——JavaScriptSerializer实现
  • 原文地址:https://www.cnblogs.com/simhare/p/901797.html
Copyright © 2011-2022 走看看