2

アクションを送信した後、div を表示または非表示にしようとしています。だから、テキストエリアがあり、そこに「例」を入れて、チェックボックスをチェックしたとしましょう。送信後、「receipt.php」ページに「example」を表示する必要があり、チェックボックスをオフにして送信した場合、receipt.php ページは「example」を非表示にする必要があります。私の問題に似た検索を試みましたが、それを解決する方法が本当にわかりません。これまでのところこのコードはありますが、「receipt.php」にはコードがありません。本当にわからないからです。助けてください

<form method ="POST" action ="receipt.php">
<textarea name ="comment"></textarea><br>
<input type="checkbox" id="checkbox" value ="1"  >Show this comment in receipt<br>
<input type ="submit" value ="Print">
</form>
4

4 に答える 4

2

サーバー側で何らかの検証がない限り、チェックボックスがオンになっているかどうかを認識するためにサーバーの応答は必要ありません。JQuery を使用している場合は、次のようにできます。

$('#checkbox').change(function(){
  $('#your_div').toggle();
});

サーバーの言うことに依存したい場合は、ajax 呼び出しに何かを返す必要があります。例: {応答: true/false}

于 2013-10-01T13:41:38.060 に答える
0

JavaScript のみを使用している場合は、次のようにしてみてください。

<script>
    function show(){
    if(form.toggledisplay.checked == false){
        document.getElementById('example').style.display = "none";
    }
    else{
       document.getElementById('div').style.display = "block";
    }
 }
</script>

<form method = "POST" action="receipt.php" onsubmit="show()">
<textarea name = "comment"></textarea><br>
<input type="checkbox" name="toggledisplay" id="checkbox" value = "1"  >Show this comment in receipt<br>
<input type = "submit" value = "Print">
</form>
<div id="example" style="display:none;">This is the div you want to show</div>

Receipt.phpdivファイルからのコンテンツを入力している場合、関数が起動されたときにポスト リクエストを作成し、次のように div のコンテンツを埋めることができます。onsubmit()

document.getElementById('div').innerHTML = "Result from the get/post request"

これがあなたを正しい方向に向けることを願っています。

于 2013-10-01T13:50:55.420 に答える
0

独自の PHP ファイルに必要なコードは次のとおりです。

<form method="POST">
    <textarea name="comment">
        <?php (isset($_POST['checkbox1']) && $_POST['checkbox1'] == '1') ? echo "Example"; : echo ""; ?>
    </textarea>
    <br>
        <label for="checkbox1">Show this comment in receipt</label>
        <input type="checkbox" id="checkbox1" name="checkbox1" value="1" />
    <br>
        <input type="submit" value="Print" />
</form>

「例」の代わりに必要なものを置き換えます。

于 2013-10-01T13:48:19.427 に答える
0

Html で:-

<form method ="POST" action ="receipt.php">
    <textarea name ="comment"></textarea><br>
    <input type="checkbox" name="reciept-chk" id="checkbox" value = "1"  >Show this comment in receipt<br>
    <input type ="submit" value ="Print">
</form>

レシート.phpで:

<?php
..//recept.php

 if(isset($_POST['reciept-chk'])){

// Write Code example here

 }

?>

値を receive.php に投稿する前にクライアント側で検証したい場合は、jquery で単純に検証できます。

$(document).ready(function(){
    $('#checkbox').change(function(){
    if ($('#checkbox').is(':checked')) {
        $("#exampleDiv").show();
    } else {
        $("#exampleDiv").hide();
    }
   });
});

1.8で廃止されたため、 toggle()は使用しないでください。

于 2013-10-01T13:41:29.503 に答える