• 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 都可以取得此值

  • 相关阅读:
    bootStrap-treeview插件
    UML常用图的几种关系的总结
    RFC中文文档
    继承:重新使用接口
    Java8向后兼容
    Java8 时间调节器
    Java8 ChronoUnits枚举
    BigDecimal.divide方法
    java.lang.Double.byteValue() 方法
    事件处理是什么?
  • 原文地址:https://www.cnblogs.com/vihone/p/1629929.html
Copyright © 2020-2023  润新知