0

我真的很震惊这里。我有一个表单,我想提交它并在 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>

现在我需要在其他页面上获取值rentals.php

$(document).ready(function() 
{
    // here I want to get copy_id value.please note this is jquery so i want to get in jquery
});
4

2 回答 2

0

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

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

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

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

于 2013-04-19T19:28:11.383 回答
0

请参考以下链接。它可以帮助您实现目标。 PHP 将变量传递到下一页

$(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;
    });
});

在rentals.php 上使用$_POST['copy_id'] 获取copy_is 的值;

于 2013-04-19T19:39:48.327 回答