移动div在Fiddle中工作,但不在我的页面中

时间:2014-12-23 17:03:49

标签: javascript jquery html css

现在,我有一个小问题:使用fiddler时。它有效,但在我的服务器上它不起作用,我不明白为什么。

http://jsfiddle.net/5mvKE/501/

我的页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <style>
  #test { 
    position: relative;
    width: 100px;
       height: 70px;
       background-color: #d2fcd9;
  }
 </style>
<script src="/scripts/jquery.min.js"></script>
<script src="/scripts/jquery-1.11.1.js"></script>
<script src="test.js"></script>
</head>

<body>
 <div id="test">test div</div>
</body>
</html>

对于脚本,我尝试将<script>放入<head><body>和外部(见上文),但没有任何作用。

我只使用了<!DOCTYPE html>(兼容的HTML 5)以及

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">`

但这不会影响结果。

1 个答案:

答案 0 :(得分:0)

您正在尝试使用哪种浏览器?

我认为这个会奏效:

$div.css({
    left: Math.floor( Math.random() * widthMax )+"px",
    top: Math.floor( Math.random() * heightMax )+"px"
});

并在$(document).ready(function(){//code});

中写下所有jquery代码