HTML (index.html):
<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>PHP (addaction.php):
<?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進行運算並即時顯示結果。
沒有留言:
張貼留言