zoukankan      html  css  js  c++  java
  • js取得后台代码值的方法

    1、将要获取的值用public属性公开,然后在js中用变量var xx = <%= PubProperty %>
    2、将值保存到一个html控件的属性中,这个属性可以自定义,例如<input type="text" id="test1"
    xxx=<%=PubProperty%>
    JS中取值 var y = document.activeElement.getAttribute("xxx");
     var y = document.getElementById('test1').getAttribute("xxx");

    例如:在aspx.cs中定义属性 ,要Page_Load()事件中要给这个属性赋值

        public string CurrentID
            {
                get { return ViewState["currID"] == null ? string.Empty : (string)ViewState["currID"]; }
                set { ViewState["currID"] = value; }
            }

    在 js中取值 的方法

    A方法:

    function OpenWindow()
            {
                var currid = <%= CurrentID %>
               // var strUrl = "AddProduct.aspx?cateId="+document.activeElement.getAttribute("cateid");
                var strUrl = "AddProduct.aspx?cateId="+document.getElementById('btnAddProduct').getAttribute("cateid");
                window.open(strUrl,"Product","statusbar=yes,width=600px,height=550px,top=0,left=0");
            }

    B:方法;在一个Html控件中自定义一个属性 cateid

    <input id="btnAddProduct" type="button" value="添加产品" cateid='<%= CurrentID %>' onclick="OpenWindow();"  /></div>

      function OpenWindow()
            {
                
               //a var strUrl = "AddProduct.aspx?cateId="+document.activeElement.getAttribute("cateid");
                //b  var strUrl = "AddProduct.aspx?cateId="+document.getElementById('btnAddProduct').getAttribute("cateid");
                window.open(strUrl,"Product","statusbar=yes,width=600px,height=550px,top=0,left=0");
            }

    a,b 都可以取得此值

  • 相关阅读:
    zznuoj 2173 春天的英雄梦
    zznuoj 2171: 春天的致富梦
    zznuoj 2169: 春天的打水梦
    zznuoj 2168 大家好 我是水题
    西安赛打铁队检讨书
    B-number HDU
    Bomb HDU
    CodeForces
    1140
    Frequent Subsets Problem
  • 原文地址:https://www.cnblogs.com/vihone/p/1629929.html
Copyright © 2011-2022 走看看