Javascript和PHP错误 [英] Javascript and php error
问题描述
我使用的网址是此
我有一个名为custom.js的javascript(jquery)文件,我在其中使用:
(function($){
$(document).ready(function(){
$('。days')。countdown({
until:directorDate,
layout:'{dn} {dl }',
时区:+7
});
$('#weather')。openWeather({
city:'directorCity //城市是一个字符串。它曾经是'纽约,美国'
placeTarget:'.weather-place',
iconTarget:'.weather-icon',
customIcons:'dark / files / img /图标/ weather /'
});
});
})(jQuery);
在我使用的标题中:
<$ ($ date)(<?php $ date = get_option('director_date');?>
<?php if($ date)p $ p>
< script> var directorDate = new Date :>
<?php echo $ date;?>
<?php endif;?>);
var directorCity =<?php $ city = get_option('director_city');?>
<?php if($ city):?>
<?php echo $ city; ?>
<?php endif; ?>< /脚本>
基本上,发生的事情是头文件从文件themeoptions.php中获取数据用户输入data.I没有显示它,因为director_city和director_date的结构都是一样的),然后custom.js从头文件获取数据。
现在倒数运行,但城市不显示。为什么?
试试在你的php中替换这行:
var directorCity =<?php $ city = get_option('director_city');?>
<?php if($ city):?>
<?php echo $ city; ?>
<?php endif; ?>
附带:
var directorCity =<?php $ city = get_option('director_city');?>
<?php if($ city):?>
<?php echo'。$ city。';; ?>
<?php endif; ?>
尝试一下,如果它不起作用,请从该php文件发送结果html。
The url i am using is this
I have got a javascript(jquery) file called custom.js in which i am using:
(function ($) {
$(document).ready(function () {
$('.days').countdown({
until: directorDate,
layout: '{dn} {dl}',
timezone: +7
});
$('#weather').openWeather({
city: 'directorCity //The city is in a string.It used to be 'New York,US'
placeTarget: '.weather-place',
iconTarget: '.weather-icon',
customIcons: 'dark/files/img/icons/weather/'
});
});
})(jQuery);
In my header i am using:
<script>var directorDate = new Date(<?php $date = get_option('director_date');?>
<?php if( $date) : ?>
<?php echo $date; ?>
<?php endif; ?>);
var directorCity = <?php $city = get_option('director_city');?>
<?php if( $city) : ?>
<?php echo $city; ?>
<?php endif; ?></script>
Basically what is happening is that the header gets the data from a file themeoptions.php (A form in the wordpress admin for a user to input data.I have not shown it because the structure of both director_city and director_date is the same there) and then custom.js gets the data from the header.
Now the countdown runs however the city is not displayed. Why is that so?
Try in your php replace this line:
var directorCity = <?php $city = get_option('director_city');?>
<?php if( $city) : ?>
<?php echo $city; ?>
<?php endif; ?>
with:
var directorCity = <?php $city = get_option('director_city');?>
<?php if( $city) : ?>
<?php echo "'".$city."';"; ?>
<?php endif; ?>
Try and if it doesn´t work, send the result html from that php file.
这篇关于Javascript和PHP错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!