0
我想在我的main.js頁面放一個包含php的jQuery函數。我能怎麼做 ?把php放在js頁面
<script type="text/javascript">
var r = parseInt('<?php the_field('red'); ?>');
var g = parseInt('<?php the_field('green'); ?>');
var b = parseInt('<?php the_field('blue'); ?>');
$("body").css('background-color', 'rgb(' + r + ',' + g + ',' + b + ')');
var alpha = Math.min($(this).scrollTop()/2000, 1);
var r = Math.round((230-parseInt('<?php the_field('red'); ?>')) * alpha + parseInt('<?php the_field('red'); ?>'));
/* red : (fin - début + début) */
var g = Math.round((230-parseInt('<?php the_field('green'); ?>')) * alpha + parseInt('<?php the_field('green'); ?>'));
/* red : (fin - début + début) */
var b = Math.round((230-parseInt('<?php the_field('blue'); ?>')) * alpha + parseInt('<?php the_field('blue'); ?>'));
$(document).scroll(function() {
/* red : (fin - début + début) */
$("body").css('background-color', 'rgb(' + r + ',' + g + ',' + b + ')');
});
</script>
你不能把php放在'core js file。(main.js)'上。 –
你會得到什麼錯誤? –
您將無法在JavaScript中執行PHP代碼,因爲這純粹是客戶端,無法在服務器上執行,但您可以使用AJAX或類似的方式調用PHP頁面並返回結果。 – HomerPlata