我在url上设置了一个条件语句,我测试了IF和ELSE,它可以用一个简单的document.write。不过,我想输出的PHP我的条件,但它只是始终输出else语句,PHP是不是我的最强的语言:JavaScript有条件的忽略IF
<script type="text/javascript">
if(
window.location.href=="mywebsite.com"
)
{
document.write('<label for="qty"><?php echo $this->__("Qty:") ?></label><input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__("Qty") ?>" class="input-text qty" />')
}else{
document.write('<label for="qty"><?php echo $this->__(' ') ?></label>
<input type="hidden" name="qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" title="<?php echo $this->__("Qty") ?>" class="input-text qty" />')
}
</script>
问题是,我在IF语句中发出了一个警告,并且它的工作原理,但是因为我在If和Else中包含'doucment.write',它只显示Else关于我是哪个页面因为我想根据特定的URL更改内容 – PhpDude
为什么你在JS中这样做呢?在PHP中执行:'if($ _SERVER ['SERVER_NAME'] =='mywebsite.com'){echo ...} else {echo ...}' – Barmar