与php的背景图象

时间:2015-07-31 05:51:42

标签: php

我想放一个背景,所有其他文字都会在上面。

我把这段代码放了,但没有工作。

<form onsubmit="prevent_duplicate(event,this);" action="">
    <input type="text" />
    <input type="submit" />
</form>
<script>
    function prevent_duplicate(event,form)
    {
       if((" "+form.className+" ").indexOf(" submitted ") > -1)
       {
          alert("can't submit more than once!!!");
          event.preventDefault();
       }
       else
       {
           form.classList.add("submitted");
       }
   }
</script>

2 个答案:

答案 0 :(得分:4)

您需要在使用之前声明$ imageUrl变量。

<?php
$imageUrl = 'http://azcombats.com/bg.jpg';
?>
<div style="height: 100%; width: 100%; background:url(<?php echo $imageUrl?>) no-repeat center center fixed">
</div>

答案 1 :(得分:0)

您无法看到图像,因为div容器的高度和宽度为零(因为它没有内容)。请将div容器的高度和宽度设置为图像的尺寸。