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

  • 相关阅读:
    windows下搭建基于eclipse插件的GoLang开发环境
    vtk类之vtkImageReslice:基本算法,对体数据沿着轴进行切片
    vtk类之vtkTextureMapToSphere:纹理映射算法, 映射球体纹理
    wxpython 之 GDI 画刷Brush(三)
    c# 获取Rss数据
    C# 基础知识系列之面向对象基础
    SilverLight 得到文件绝对路径
    SilverLight C# 读取并修改App.config文件
    Silverlight 脱离浏览器
    C# 中New关键字的用法
  • 原文地址:https://www.cnblogs.com/vihone/p/1629929.html
Copyright © 2011-2022 走看看