2015-05-09 67 views
-1

我已经为html表单上的提交按钮的位置生成了2个随机值。提交按钮的随机位置

我该如何使用它们?

我想要的是随机定位一个提交按钮!

+0

请发表你有什么到目前为止已经试过。 – Banana

+0

我卡住了......我可以使用CSS来定位任何元素,但不知道如何随机地做到这一点。 css是否读取php变量? – stilts77

+0

我明白你被卡住了,这不是我所问的。请在您的问题中发布您迄今为止尝试解决此问题的方法...... – Banana

回答

0

使用.style属性:

var btn = document.getElementById("btn"); 
 
btn.style.top = Math.floor((Math.random() * 230) + 1) + "px"; 
 
btn.style.left = Math.floor((Math.random() * 200) + 1) + "px";
input[type='submit'] { 
 
     position: absolute; 
 
    }
<input type="submit" id="btn" value="Button!" />

+0

太好了 - 非常感谢。 – stilts77

+0

我在哪里包含这些代码?在身体的第一个 -