js调用php和php调用js的方法举例
1、<!--js调用php--><?phpif($_GET["action"]=="ok"){echo "I'm OK!";}else{echo "I'm not OK!";}?><SCRIPT Language = "JavaScript">function func(){if(confirm("Are you OK with this?")){this.location = "ok.php?action=ok";}else{this.location = "ok.php?action=cancel";}}</SCRIPT><html><head></head><body><a href="#" href="#" onClick="javascript:func();">Please Click</a></body></html><!--js调用php--><html><head><script>function isMail(PostString){re=/\w*/if(re.test(PostString)){return true;}else{return false;}}function test(){if (isMail(<?php echo $email?>)){document.write("<?php echo "N";?>");}else{document.write('<?php echo 'Y';?>');}}</script></head><body><?php$email="aa";?><input type=button value=click onclick= 'test() '></body></html>
2、<!--php中含有js代码--><?php echo "<script language=javascript> function test(){ alert( 'hello '); }</script> ";?><input type=button value=click onclick= 'test() '>