php と css だけでこれを実現できますが、ajax を使用すると滑らかになります。JSON を使用して、.js から .php へ、およびその逆にデータを解析します。jQuery はこれをとても簡単にします (を使用$.post
)
$(document).ready(function() {
$.post('calculate.php', { value: $('td') }, //posts value to php
function(data) {
if(data.success) {
alert(data.result); //gets the value $result from php
}
else {
alert('error');
}
}, 'json');
});
これにより、td の値が calculate.php に送信され、JSON データを計算してエコー出力することができます。
$value = $_POST['value'];//assign value from js to $value
.....
$data['success'] = true; //there was no error
$data['result'] = $result; //where $result is calculated within php
echo json_encode($data);
js ファイルと php ファイルの間で多くの変数を渡すことができます。結果をアニメーション化することもできます。
これらのリンクが役立つかもしれません
http://davidwalsh.name/animated-ajax-jquery
http://www.9lessons.info/2009/08/jquery-and-ajax-best-demos-part-3.html
http://www.noupe.com/ajax/30-fresh-ajax-tutorials-and-techniques.html