1

以下に、PHPフォームの変数をjavascriptのオブジェクトのリストに保存する関数があります

a.js

function save()
{
    var oldItems = JSON.parse(localStorage.getItem('itemsArray')) || [];

    var newItem = 
    {
        'num' : document.getElementById("num").value,
        'methv' : document.getElementById("methv").value,
        'q1' : document.getElementById("q1").value,
        'q2' : document.getElementById("q2").value,
        'q3' : document.getElementById("q3").value,
        'q4' : document.getElementById("q4").value,
        'comm' : document.getElementById("comm").value
    };

    oldItems.push(newItem);

    localStorage.setItem('itemsArray', JSON.stringify(oldItems));
}

php ページにコンテンツを表示して編集できるようにするにはどうすればよいですか? (印刷されたものの例は大歓迎です)

編集*

これらは、オブジェクトに追加される値です

<form action="" method="post" enctype="multipart/form-data">

  <select name="methv" class="textfields" id="methv" style="width:110px" > 
    <option value= "dont know">dont know </option>

<select name="q1" class="textfields" id="q1" style="width:50px" > 
<option value= "-">-</option>
<option value= "L">L</option>

<select name="q2" class="textfields" id="q2" style="width:50px" > 
<option value= "-">-</option>
<option value= "L">L</option>

<select name="q3" class="textfields" id="q3" style="width:50px" > 
<option value= "-">-</option>
<option value= "L">L</option>

<select name="q4" class="textfields" id="q4" style="width:50px" > 
<option value= "-">-</option>
<option value= "L">L</option>

<textarea rows="4" cols="40" id="comm" name="comm" style="width:300px"><?php echo $post['addcomment'] ;?></textarea> 

</form>

私は a.js だけをインポートしました<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

4

3 に答える 3

1

You seem to be confusing the roles of PHP and Javascript.

PHP is server-side, meaning that it renders the page (and does any calculations, database calls, etc, if necessary), and then outputs HTML. This is the end of PHP's involvement in a web page.

Javascript is client-side, meaning after a page has been loaded and rendered in a browser, Javascript can get to work modifying elements of the page, if you'd like.

You haven't included any information about the current page structure, so there is nothing we can offer to help you modify your page content using javascript.

于 2013-03-14T19:31:50.283 に答える
0

サーバー上の PHP スクリプトがそのデータを処理するには、GET または POST 要求を介してサーバーにデータを送信する必要があります。JavaScript と localStorage だけにある限り、サーバー (および PHP) はそれが存在することを認識しません。

于 2013-03-14T19:31:33.547 に答える
0

PSTこれはどうですか?

コードを送信するときは、関数の保存をこすります。

<form action="" onsubmit="save()" method="post" enctype="multipart/form-data">

そして、次のようなフォームタグを追加します

<textarea id="SendToPhp" style="display : none"></textarea>

そして、保存機能で、これを最後に追加します

document.getElementById('SendToPhp').innerHTML = object;

またはそのようなもの!

しかし、私はこれがあなたが欠けているものです!

フォームの最後に次を追加しますが、タグ<input type="submit" value="Send To PHP" />内に保持して、<form>直前に配置してください</form>

このボタンをクリックすると、アクションexaction = "readjs.php"とそのページにあるはずのphpページに送信されますprint_r($_POST)

必要な値は POST に保存されます。

ページをリロードせずに実行したい場合は、AJAX を詳しく調べる必要があります。

これが何らかの形で役立つことを願っています。

EDITED CODE、以前は $_GET だった $_POST である必要があります

于 2013-03-14T19:55:20.743 に答える