Javascript和php错误
我使用的url是 我有一个名为custom.js的javascript(jquery)文件,我在其中使用:Javascript和php错误,javascript,php,wordpress,function,Javascript,Php,Wordpress,Function,我使用的url是 我有一个名为custom.js的javascript(jquery)文件,我在其中使用: (function ($) { $(document).ready(function () { $('.days').countdown({ until: directorDate, layout: '{dn} {dl}', timezone: +7 }); $(
(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);
<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>
在我的标题中,我使用了:
(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);
<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>
var directorDate=新日期(
);
var直接性=
基本上,标题从文件themeoptions.php(wordpress admin中的一个表单,用于用户输入数据。我没有显示它,因为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=
与:
var directorCity=
这行看起来不正确:city:'directorCity//city是一个字符串。它以前是“美国纽约”
。它将所有行作为字符串读取(可能在第二个单引号后的N处抛出一个错误?)
听起来像是在查找存放在directoryCity
中的目录城市名称,所以请尝试将该行更改为city:directoryCity,
如果这不起作用,您能在javascript控制台中检查错误,如果有,发布错误吗?由director\u date
返回的值的格式是什么,是字符串还是int,还是什么?如果它是一个字符串,你不能用引号括起来。它是一个字符串,用代码括起来,但不起作用。非常感谢。让我来检查一下。我会给你赏金的,它有用吗?您需要字符串中的“”才能让javascript知道它是字符串。是的,我得到了它,但它在本地工作。现在我正在现场测试。这需要几分钟。你可以像这样清理回声:谢谢你@adearriba它成功了。这是你的赏金。等等,我必须再等23个小时。这是规则