日期:2014-05-20  浏览次数:20495 次

页面与JS脚本之间传值问题!!!!!
打开数据时在ASP中可以这样,
<script   language= "javascript ">
<%=1%>
</script>
↑这样asp.net也能做到,
<script   language= "javascript ">
<%#DataBinder.Eval(Container.DataItem, "1 ").ToString()%>
</script>
但是

如果是如果是页面传过来的值呢.比如1.aspx?id=123&op=321

那在JS里应该怎么接收传过来的值呢?
<script   language= "javascript ">
// <%=1%> (JS如何接收页面传过来的值放在这?asp.net版本.)
</script>


------解决方案--------------------
Create public server varible

public string ID;
...
ID = Request.QueryString[ "id "];

In aspx:
<script language= "javascript ">
<%=ID%>
</script>

OR

Parse your url in javascript
url = window.location;
then parse url...

------解决方案--------------------
后台先获得传回来的值,再 <%=后台值%>
------解决方案--------------------
1: <script language=”JavaScript”>
2: var urlParts = document.URL.split( "? ");//把1.aspx?id=123&op=321 看做字符串,将以?拆开此字符串
3: var parameterParts = urlParts[1].split( "& ");//获取id=123&op=321 下标1 然后将其分为[0]=id=123 [1]=op=321
4: for (i = 0; i < parameterParts.length; i++) { //循环数量,再次拆分
5: var pairParts = parameterParts[i].split( "0 ");
6: var pairName = pairParts[0];
7: var pairValue = pairParts[1];
8: document.write(pairName + “ :“ +pairValue );
9: }
10: </script>