我需要帮助window.location=
echo
与PHP
一起使用echo
'<div class="adsa">
<div class="adimg125" style="'.$stylea.'">
<div onclick="event.cancelBubble=true;if (event.stopPropagation) event.stopPropagation(); window.location='.$url.'" class="check" style="'.$check.'">Check Monitors</div>
</div>
</div>';
。这是我的代码:
<div class="check" onclick="event.cancelBubble=true;if (event.stopPropagation) event.stopPropagation(); window.location=/index.php?key=perfectdeposit.biz" style="background: #767a81 none repeat scroll 0 0; color: white; cursor: pointer; display: none; font-size: 13px; padding: 2px 0 3px; position: relative; text-align: center; top: -132px; width: 117px; margin-left: 38px">Check Monitors</div>
我的数据显示正常,但链接不起作用意味着它没有显示在&#39; &#39;打开链接。这是我显示的数据
window.location=/index.php?key=perfectdeposit.biz
你可以看到这里没有显示&#39; &#39;在那一行
window.location='/index.php?key=perfectdeposit.biz'
需要像这样显示
http://samples.openweathermap.org/data/2.5/weather?q=London,uk
答案 0 :(得分:2)
看起来你需要在PHP中转义这些字符。也许是这样的?
echo'<div class="adsa"><div class="adimg125" style="'.$stylea.'">
<div onclick="event.cancelBubble=true;if (event.stopPropagation) event.stopPropagation(); window.location=\''.$url.'\'" class="check" style="'.$check.'">Check Monitors</div>
</div></div>';
请注意\
附近的window.location
。
这是输出:
$stylea = 'something';
$url = 'http://google.com';
$check = 'test';
<div class="adsa"><div class="adimg125" style="something">
<div onclick="event.cancelBubble=true;if (event.stopPropagation) event.stopPropagation(); window.location='http://google.com'" class="check" style="test">Check Monitors</div>
</div></div>
答案 1 :(得分:0)
我通常使用heredoc来避免引用错误,即:
echo <<< EOF
<div class="adsa"><div class="adimg125" style="$stylea">
<div onclick="event.cancelBubble=true;if (event.stopPropagation) event.stopPropagation(); window.location='$url' class="check" style="$check">Check Monitors</div>
</div>
EOF;
输出:
<div class="adsa"><div class="adimg125" style="some_style">
<div onclick="event.cancelBubble=true;if (event.stopPropagation) event.stopPropagation(); window.location='/index.php?key=perfectdeposit.biz' class="check" style="something">Check Monitors</div>
</div>