简单的PHP字符串检查不起作用
Simple PHP string check not working
我甚至不想发布这个问题,但我似乎无法解决这个问题。我可以在if
语句之前直接回显$the_page
,但if
语句总是出现"else
"。有什么想法吗?提前谢谢。
<?php if(is_page('sp')){$the_page = 1;} else { };
if($the_page === 1) { ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$("#form-interest option:first:contains('---')").html('Área De Interés*:');
});
</script>
<?php } else { ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$("#form-interest option:first:contains('---')").html('Area of Interest*:');
});
</script>
<?php } ?>
编辑:利用你的一些想法,我把它清理得更干净了。is_page()是一个Wordpress调用,使用此修订版,我可以正确打印西班牙语"Ir al-Inicio"(因此is_page函数必须正常工作),但$interest并没有按应有的方式打印"Área De Interés*:"。else
正在正确输出文本和$interest
字符串。
<?php if(is_page('sp')) { $interest = 'Área De Interés*:'; ?>
Ir al Inicio
<?php } else { $interest = 'Area of Interest*:'; ?>
SCROLL TO TOP
<?php } ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
var interest = '<?php echo $interest; ?>';
$("#form-interest option:first:contains('---')").html(interest);
});
</script>
参考我的最后一条评论:我确信某个地方存在JavaScript错误。如果检查源代码,就会正确设置变量,因此PHP可以正常工作。
查看Chrome中的JavaScript控制台,我看到以下错误消息,它只出现在西班牙语版本中,因此它是进一步调查的理想候选者:
Uncaught TypeError: Cannot read property 'match' of undefined in jquery.easytabs.min.js?ver=3.2.0:12
我刚刚运行了基本的if语句:
<?php
$the_page=1;
if($the_page === 1) {
echo "1: '$the_page=$the_page";
}
else{
echo "else: '$the_page=$the_page";
}
//echos "1: $the_page=1"
然后
<?php
$the_page=frenchfry;
if($the_page === 1) {
echo "1: '$the_page=$the_page";
}
else{
echo "else: '$the_page=$the_page";
}
//echoes else: $the_page=frenchfry
我认为问题出在is_page('sp')
上;你说你可以回显它并验证它是数字1
吗?
检查您的条件if(is_page('sp'))
,这肯定会返回false
,所以您的变量$the_page
不会设置为1,所以它总是出现在else statement
中。
在我看来,您正在关闭语句上的php标记,因此它同时运行,因为它们都是纯html格式的。你只看到最后一个,因为它发生在最后。试试这个:
<?php if(is_page('sp')){$the_page = 1;} else { };
if($the_page === 1) {
echo "<script type='text/javascript'>".
"jQuery(document).ready(function($) {".
"$('#form-interest option:first:contains('---')').html('Área De Interés*:');".
"});".
"</script>";
<?php } else {
echo "<script type='text/javascript'>" .
"jQuery(document).ready(function($) {".
"$('#form-interest option:first:contains('---')').html('Area of Interest*:');".
"});".
"</script>";
}
?>
你似乎在语法上有点困惑,所以希望这有点道理。
相关文章:
- 使用map来检查是否为真'不起作用
- 错误检查在Javascript中不起作用
- 对照数组脚本检查文本框中的值不起作用
- JS中的单选按钮检查不起作用
- 为什么这个jQuery代码检查所有复选框不起作用
- 简单的PHP字符串检查不起作用
- 引导程序3在IE8中不起作用(已检查其他答案)
- 我需要让用户输入他的出生日期,并使用javascript检查其形式是否正确.我的代码不起作用
- 我的数字检查器功能不起作用,为什么
- If.else语句检查NaN和空字符串是否在JavaScript中不起作用
- javascript对象检查在IE11中不起作用
- 互联网连接检查不起作用
- 溢出检查不起作用
- 图像存在性检查不起作用
- Live用户名检查不起作用
- 在Angular/Restangular中对返回的JSON值进行空检查不起作用
- 正则表达式-整数检查不起作用
- jQuery.pr()检查不起作用
- 简单的JavaScript检查不起作用
- 使用jQuery进行电子邮件检查不起作用