在查询字符串中将隐藏字段从一个页面传递到另一个页面 [英] Passing hidden field from one page to another in querystring

查看:39
本文介绍了在查询字符串中将隐藏字段从一个页面传递到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过查询字符串将隐藏文件中的查询从一页传递到另一页.谁能帮我解决逻辑问题?

I want to pass a query in a hidden filed from 1 page to another by querystring. Can anyone help me out with the logic?

推荐答案

值得花时间学习 jQuery.它不是很复杂,它使编写 javascript 变得更加容易.还有很多jQuery插件,比如jquery.url.

It's worth taking the time to learn jQuery. It's not very complicated, and it makes writing javascript much easier. There are also many jQuery plugins, such as jquery.url.

此外,正如其他海报所建议的那样,如果您关心向用户显示隐藏字段的值,则可能不希望将隐藏字段的值放入查询字符串中.但是,如果数据存在于隐藏字段中,用户只要愿意查看,总是有可能找到它的.

Also, as other posters have suggested, you may not wish to put the hidden field's value in the query string if you care about it being displayed to the user. However, if the data is present in a hidden field it will always be possible for a user to find it if they care to look.

如果您确实想将隐藏字段放在查询字符串中,然后通过非 jQuery javascript 提取它:

If you really do want to put the hidden field in the query string and then extract it via non-jQuery javascript:

hiddenFieldPage.aspx

此表单将在提交时将用户带到 processingPage.aspx?datum=someValue.如果同时不需要提交其他任何内容,您也可以使用普通链接.

This form will take the user to processingPage.aspx?datum=someValue when it is submitted. You could probably also just use an ordinary link if nothing else needs to be submitted at the same time.

<form method="GET" action="processingPage.aspx">
    <input type="hidden" name="datum" value="someValue">
    <input type="submit">
</form>

或者,从代码隐藏中插入值:

or, inserting the value from code-behind:

RegisterHiddenField("datum", "someValue");

processingPage.aspx

此脚本将弹出一个警告框,其值为 URL 中的datum" - 假设表单的方法设置为GET":

This script will pop-up an alert box with the value of "datum" from the URL - assuming the form's method is set to "GET":

    <script type="text/javascript">

        function getUrlParam( key ) {

            // Get the query and split it into its constituent params
            var query = window.location.search.substring(1);
            var params = query.split('&');

            // Loop through the params till we find the one we want
            for( var i in params ) { 
                var keyValue = params[i].split('=');
                if( key == keyValue[0] ) {
                    return keyValue[1];
                }
            }

            // Didn't find it, so return null
            return null;
        }

        alert( getUrlParam("datum") );
    </script>

如果表单的方法设置为POST"(在 ASP.NET 中通常如此),则datum"将不会出现在查询字符串中,您必须再次将其放置在页面上:

If the form's method was set to "POST" (as it usually would be in ASP.NET), then "datum" won't be in the query string and you'll have to place it on the page again:

RegisterHiddenField( "datum", Request.Form["datum"] );

要检索第二页上的隐藏值:

To retrieve the hidden value on the second page:

var datum = document.Form1.item("datum").value;
alert( datum );

这篇关于在查询字符串中将隐藏字段从一个页面传递到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆