小编use*_*152的帖子

让图像在点击时随机移动

我正在尝试使用纯 JavaScript 使图像随机移动。onclick 事件发生后,图像位置应根据生成的随机数移动。

这是我的代码:

<html>
<head><title> Move Image </title>

<style type="text/css">
#smiley { position: relative; top: 0px; left: 0px; }
</style>

<script type="text/javascript">

function changeImg()
{
var x = Math.floor(Math.random()*300);
var y = Math.floor(Math.random()*300);


var obj = document.getElementById("emotion");

obj.style.top = x + "px";
obj.style.left = y + "px";


 obj.onclick= "changeImg();"
 }

</script>
</head>
<body>
<img id="emotion" 
src="http://www.google.com/images/srpr/logo4w.png" 
width="42" height="42">
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

任何想法?谢谢你!

html javascript css image move

5
推荐指数
1
解决办法
7667
查看次数

JavaScript相当于jQuery的keyup()和keydown()

我在stackoverflow上看过这个链接:$(document).ready等效没有jQuery

在我的背景下,我正在使用

$(document).keydown(Keypress);
$(document).keyup(Keyoff);
Run Code Online (Sandbox Code Playgroud)

为了功能

 function Keypress(evt) {
     if (evt.keyCode == 39) rightpress = true;
     else if (evt.keyCode == 37) leftpress = true;
 }

 //unset
 function Keyoff(evt) {
     if (evt.keyCode == 39) rightpress = false;
     else if (evt.keyCode == 37) leftpress = false;
 }
Run Code Online (Sandbox Code Playgroud)

有javascript等价吗?喜欢window.onload?

html javascript css jquery keypress

4
推荐指数
1
解决办法
5910
查看次数

htaccess 内部服务器错误,身份验证循环

我正在尝试设置 htaccess 以限制对特定文件夹的访问。我目前有以下几点:

访问:

AuthType Basic
AuthName "Restricted area"
AuthUserFile /home3/user/public_html/.htpasswd
require valid-user

ErrorDocument 404 "Error"
ErrorDocument 401 "Error"
ErrorDocument 403 "Error"
Run Code Online (Sandbox Code Playgroud)

密码:

Guest:GuestPassword
Run Code Online (Sandbox Code Playgroud)

使用这种方法,我要么返回 500 服务器错误,要么循环并不断提示我进行身份验证。

任何帮助表示赞赏!

另外:我使用showphp()来获取文档根目录。所以 AuthUserFile 路径应该是正确的。

谢谢!

php .htaccess web

3
推荐指数
1
解决办法
1609
查看次数

标签 统计

css ×2

html ×2

javascript ×2

.htaccess ×1

image ×1

jquery ×1

keypress ×1

move ×1

php ×1

web ×1