我需要先将PHP
数组更改为JS
数组:
$url = "web.com";
<script type="text/javascript">
var url = <?php echo json_encode($url); ?>;
</script>
现在使用Javascript
/ JQuery
,我需要执行此操作:
if(strpos($url, "com") !== false){
echo "<p><b style="background-color:blue; color:white;">TEST</b></p>";
}
else{
echo "<p><b style="background-color:yellow; color:white;">TEST</b></p>";
}
我该怎么做?
答案 0 :(得分:-1)
var url = location.href;
var child = document.createElement('div');
if(url.indexOf("com") != -1) {
str = '<p><b style="background-color:blue; color:white;">TEST</b></p>';
} else {
str = '<p><b style="background-color:yellow; color:white;">TEST</b></p>';
}
child.innerHTML = str;
child = child.firstChild;
document.getElementById('test').appendChild(child);
<div id="test"></div>