<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="jobs_Default3" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>无标题页</title>
    <script language="javascript" type="text/javascript">
      var txtTestValue
   
        function GetUrl1()
     
    {
        if( document.getElementById("ddlTest1").SelectedIndex == "0" )
        {
        txtTestValue ="&getTXT=" & document.getElementById("TextBox1").value;
            document.getElementById("myhref").href="aaa.aspx?id=" + txtTestValue ;
        }
        else ( document.getElementById("ddlTest1").SelectedIndex == "1" )
        {
            txtTestValue = "";
            document.getElementById("myhref").href="aaa.aspx?id=" + txtTestValue;
              
        }
        
    }    </script>
               
</head>
<body>
    <form runat="server" id="form1" method="post" enctype="multipart/form-data">
    <div>
     <a href='' id="myhref" name="myhref" onmouseover="GetUrl1()">链接</a><br />
         <asp:RadioButtonList ID="ddlTest1"  runat="server" ForeColor="Fuchsia"
            RepeatDirection="Horizontal"  Width="152px" EnableViewState="true"  >
            <asp:ListItem   Selected="True">选择1</asp:ListItem>
            <asp:ListItem    Text="false">选择2</asp:ListItem>
        </asp:RadioButtonList>
        <asp:TextBox ID="TextBox1" runat="server"   Width="110px"></asp:TextBox>
        
    </div>
    </form>  
</body>
</html>1、后台有个公共变量publicstring,假设publicstring="ID1234"
2、前台网页通过js获得变量txtTestValue (如上),
当选择1时就txtTestValue就获取textbox里的值,当选择2时txtTestValue =""空值,再使txtTestValue 与publicstring接起来,即是想publicstring & txtTestValue   然后使用document.getElementById("myhref").href="aaa.aspx?id=" + publicstring & txtTestValue 如何实现我想要的.

解决方案 »

  1.   

    不考虑安全性的因素,你可以直接把publicstring隐藏的写在网页中,在js中直接调用就可以了或者是通过ajax动态调用后台数据信息
      

  2.   

    不是很明白楼主的意思.试试这样.public publicstirng = "ID1234";在脚本
    var publicstring=<%=publicstring%>;
      

  3.   

    我先不考虑后台变量,就是通过js处理变量,我都还没有做成功.昨晚试了一晚,常会这样,不管选择1还是选择2,txtTestValue的值都是textbox的值,不能为空,太不像话了.气人哦.
      

  4.   

    Page_load的时候
    TextBox1.Text = publicString
      

  5.   

    <head   id="Head1"   runat="server"> 
            <title> 无标题页 </title> 
            <script   language="javascript"   type="text/javascript"> 
                var   txtTestValue 
                function   GetUrl1() 
                { 
                    var rd1 = document.getElementById("rad1");
                    var rd2 = document.getElementById("rad2");
                    var txt = document.getElementById("TextBox1");
                    var myhref = document.getElementById("myhref");
                   alert(txt.value);
                    if(rd1.checked == true) 
                    { 
                       myhref.href = "aaa.aspx?id="+txt.value;
                   
                    } 
                    else
                    { 
                        //txt.value =   ""; 
                        myhref.href = "aaa.aspx?id="; 
                    } 
                         alert(myhref.href);
                } 
            </script> 
    </head> 
    <body> 
            <form   runat="server"   id="form1"   method="post"   enctype="multipart/form-data"> &nbsp;
            <a id="myhref">URL</a>
            <asp:RadioButton ID="rad1" runat="server" GroupName="rd1" onclick="GetUrl1()" Text="选择1" />
                <asp:RadioButton ID="rad2" runat="server" GroupName="rd1" onclick="GetUrl1()" Text="选择2" />
                <br />
                    <asp:TextBox   ID="TextBox1"   runat="server"       Width="110px"> </asp:TextBox> 
                       
            </form>     
    </body> 
    </html> 
      

  6.   

    txtTestValue   ="&getTXT="   &   document.getElementById("TextBox1").value; 
    是不是这里的问题?txtTestValue   ="&getTXT= &"   document.getElementById("TextBox1").value; 
      

  7.   

    <script   language="javascript"   type="text/javascript"> 
                var   txtTestValue; 
          
                    function   GetUrl1() 
              
            { 
                    if(document.getElementById("ddlTest1").value == "0") 
                    { 
                            txtTestValue   ="&getTXT="   +   document.getElementById("TextBox1").value; 
                            document.getElementById("myhref").href="aaa.aspx?id=" + <%= publicstring%> + txtTestValue   ; 
                    } 
                    else   (document.getElementById("ddlTest1").value == "1") 
                    { 
                            txtTestValue   =   ""; 
                            document.getElementById("myhref").href="aaa.aspx?id=" + <%= publicstring%> + txtTestValue; 
                                
                    } 
                    
            }         </script> 
      

  8.   

    取后台变量可以用<%=变量名%>
    还有,JS里面的连接符不是&,是+,部分代码如下面:
    txtTestValue   ="&getTXT="   +   document.getElementById("TextBox1").value; 
      

  9.   

    我通过前台这样<a><%=   publicstring%></a>后台参数,在JS里用 var  txtTestValue=<%=publicstring %>;可js里的txtTestValue值与<%=publicstring%>值是不一样的,txtTestValue值是undefined.后台的publicstring不管是什么值而txtTestValue不变是undefined.这样下去,做死人的!!!!!!!!!!!!!!????
      

  10.   

    写在这种形式 var txtValue='<%=url %>';
    试下
    var txtTestValue= '<%=publicstring%>';