HTML (index.html):
1 2 3 4 5 6 7 8 9 10 11 12 | <script src= "jquery-1.6.1.min.js" type= "text/javascript" ></script> <script type= "text/javascript" > $(document).ready( function (){ $( "#myCount" ).click( function (){ $( "#myText" ).load( "addaction.php" , { "num1" :$( "#number1" ).val(), "num2" :$( "#number2" ).val()}); }); }); </script> <textarea id= "number1" cols= "20" rows= "3" >1</textarea><br /> <input type= "text" id= "number2" value= "2" /><br /> <input type= "button" id= "myCount" value= "Send" /> <div id= "myText" ></div> |
1 2 3 4 5 6 | <?php $num1 = ! empty ( $_POST [ 'num1' ]) ? $_POST [ 'num1' ] : null; $num2 = ! empty ( $_POST [ 'num2' ]) ? $_POST [ 'num2' ] : null; $total = $num1 + $num2 ; echo $num1 . "+" . $num2 . "=" . $total ; ?> |
採input text以及texterea進行範例演示,
使用jQuery Load傳遞POST給PHP進行運算並即時顯示結果。
沒有留言:
張貼留言