Javascript和PHP错误 [英] Javascript and php error

查看:96
本文介绍了Javascript和PHP错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的网址是



我有一个名为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆