我想在标签外部显示一个javascript函数,在标签内部也能工作,但我需要离开它们。
如何通过?
我在WORDPRESS:中的PHP代码
function custom_shortcode3() {
$conecta3 = mysql_connect("localhost", "mcommerce", "kaishek") or print (mysql_error());
mysql_select_db("mcommerc_whmcs", $conecta3) or print(mysql_error());
function mysql_get_var3($query,$y=0){
$res = mysql_query($query);
$row = mysql_fetch_array($res);
mysql_free_result($res);
$rec = $row[$y];
return $rec;
}
?>
<html>
<div id="show"></div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function total() {
setInterval(function () {
$('#show').load('datatotaldeprodutos.php')
}, 1000);
};
<?
echo "total();"; //WORK BUT NOT APPEAR IN WORDPRESS
?>
</script>
</html>
<?
echo "total();"; //NOT WORKKK
echo "test"; //WORK, APPEAR IN WORDPRESS. i need the function appear
}
add_shortcode( 'totaldeprodutos', 'custom_shortcode3' );
我不明白为什么不在JavaScript中运行函数。PHP是一种服务器端语言,不能访问用JS编写的函数。
<script type="text/javascript">
function total() {
setInterval(function () {
$('#show').load('datatotaldeprodutos.php')
}, 1000);
};
total(); // run the function
</script>