以jquery形式获取值

以jquery形式获取值,jquery,get,Jquery,Get,我真的被打动了。我有一个表单,我想提交它并在Jquery中的其他表单上获取值: <form id="rentals_form" name="popup_form" action="rentals.php" method="POST"> <input alt="" style="display:none;" id="copy_id" name="copy_id" type="text"> </form> <button class="s

我真的被打动了。我有一个表单,我想提交它并在Jquery中的其他表单上获取值:

<form id="rentals_form" name="popup_form" action="rentals.php" method="POST">
    <input alt="" style="display:none;" id="copy_id" name="copy_id" type="text">
</form>

<button 
    class="save_button" 
    value="copy_listing_button" 
    onclick="document.forms[$('#copy_listing option:selected').val()+'_form'].submit();" 
    style="font-size:11px; padding:0 3px 0 3px;">
        Go
</button>

当您按下menu.html中的任何按钮a、b或c时,您说它加载index.html。所以,一旦在浏览器中加载index.html,就不会有当前dom中上一页的任何按钮的历史记录

您需要做的是从menu.html提交信息,然后在index.html中使用这些信息。。请参阅表单提交,或至少请求参数

您可以使用“window.location”并搜索字符串访问index.html上javascript中的请求参数


编辑:我看到你更新了问题。请参阅下面发布的关于使用php访问请求参数的其他答案。

请参阅以下链接。它可以帮助你实现你的目标。


在rentals.php上,获取copy_的值时使用$_POST['copy_id']

Javascript变量不会在不同的页面上持久存在。如果需要保存数据,请使用cookies或LocalStorage.copy\u id是control not js variable…我想得到这个控制值您已经完全重写了这个问题。我刚才提到的问题是关于在点击按钮时设置变量的。是的,我现在说得很清楚,请阅读。您可以使用ajax调用,在该调用中,您可以定义需要重定向的URL,您可以获得类似$u post['var1'这样的变量或者您也可以使用rentals.php重定向页面?Copy_id=1并在第二页上获取该变量!或者,如果您不想让用户看到URL中的copy_id值,您可以使用session变量。我提到过,我不想使用php…我想使用rentals.php中的jquery…我想使用jquery函数
$(document).ready(function() 
{
    // here I want to get copy_id value.please note this is jquery so i want to get in jquery
});
$(document).ready(function() {
    $('#button_ID').live('click',function(e){
        e.preventDefault();
        var currentId = $(this).attr('id'); 
        var form_id = $('#'+currentId).closest('form').attr('id');
        var copy_id = $("#"+form_id+" input[name=copy_id]").val();

        $.post('rentals.php', { copy_id : copy_id }, function (data) {  
            alert(data);
        }, 'json'); 
        return false;
    });
});