- <?php
- $c = 0;
- if(isset($_POST["a"]) && isset($_POST["b"]) && $_POST["a"] != "" && $_POST["b"] != ""){
- $c = $_POST["a"] + $_POST["b"];
- if(isset($_POST["i"]) && $_POST["i"] == "true")
- {
- echo($c);
- die();
- }
- }
- ?>
- <html>
- <form action="test.php" method="post">
- <input type="text" id="a" name="a">
- +
- <input type="text" id="b" name="b">
- <input type="submit" id="s" value="=(php)">
- <input type="button" id="btn" value="=(JS)" onclick="add()">
- </form>
- <div id="re"><?php echo($c)?></div>
- </html>
- <script
- src="https://code.jquery.com/jquery-3.5.1.js"
- integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
- crossorigin="anonymous"></script>
- <script>
- function add(){
- $.post( "test.php",{a:$("#a").val() , b:$("#b").val() , i:"true"} , function( data ) {
- $( "#re" ).html( data );
- });
- }
- </script>
複製代碼 |