我有一个小div标签,当我点击它(onClick事件)时,它将运行该printMousePos()功能.这是HTML标签:
<html>
<header>
<!-- By the way, this is not the actual html file, just a generic example. -->
<script src='game.js'></script>
</header>
<body>
<div id="example">
<p id="test">x: , y:</p>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是一个单独的.js文件中的printMousePos函数:
function printMousePos() {
var cursorX;
var cursorY;
document.onmousemove = function(e){
cursorX = e.pageX;
cursorY = e.pageY;
}
document.getElementById('test').innerHTML = "x: " + cursorX + ", y: " + cursorY;
}
Run Code Online (Sandbox Code Playgroud)
是的,该函数实际上有效(它知道你何时点击它和所有),但它返回x和y的未定义,所以我假设函数中的get x和y代码是不正确的.有任何想法吗?我也知道javascript本身没有任何内置函数可以像java一样返回x和y,ex ..有没有办法用JQuery或php做到这一点?(尽管可能,尽量避免那些,javascript会是最好的).谢谢!
我无法将 GPA 双精度舍入到小数点后两位。(前 GPA 需要四舍五入:3.67924)我目前正在使用 ceil 进行四舍五入,但它目前将其输出为整数 (368)
这是我现在拥有的
if (cin >> gpa) {
if (gpa >= 0 && gpa <= 5) {
// valid number
gpa = ceil(gpa * 100);
break;
} else {
cout << "Please enter a valid GPA (0.00 - 5.00)" << endl;
cout << "GPA: ";
}
}
Run Code Online (Sandbox Code Playgroud)
将上面的代码与 3.67924 一起使用将输出 368(这是我想要的,但只是没有整数和小数之间的句点)。我怎样才能解决这个问题?
我有一个类项目的假配置文件系统,它需要一个配置文件图片,它需要一个选项来在本地(从您的硬盘驱动器)更改它.我有一个工作img标记,它将占位符图像保存为默认值,当您单击时change picture,将打开一个打开的文件对话框.我现在需要工作的是img使用他们选择的图像设置标签的图像链接.这就是我到目前为止所拥有的.
<div id="userphoto">
<a><div class="gravatar-wrapper-128"><img id="image" src="http://blog.ramboll.com/fehmarnbelt/wp-content/themes/ramboll2/images/profile-img.jpg" alt="" class="logo" width="120" height="120"></div></a>
<div class="change-picture-slide" style="top: 30px;">
<input accept="image/*" type="file" id="upload" name="upload" style="visibility: hidden; width: 1px; height: 1px" />
<a href="" onclick="changePicture(); return false">Change Picture</a>
</div>
</div>
<script>
function changePicture() {
//open the open file dialog
document.getElementById('upload').click();
var link = document.getElementById('upload').url;
//change picture
var img = document.getElementById("image");
img.src = link;
}
</script>
Run Code Online (Sandbox Code Playgroud)
知道这一点无法完成,我怎样才能将用户选择的图像匿名上传到imgur并使用此链接?
我有一个字段,您可以在其中输入您的姓名并提交。我希望接收人的名字和姓氏,为此,我需要检查值是否至少包含2个字。这就是我现在正在使用的东西,但是似乎没有用。
function validateNameNumber(name) {
var NAME = name.value;
var matches = NAME.match(/\b[^\d\s]+\b/g);
if (matches && matches.length >= 2) {
//two or more words
return true;
} else {
//not enough words
return false;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个视频游戏,我有一个可以恢复健康的for循环
public void recoverHealth() {
if (curHealth < finalHealth) {
for (double i = 0; i < finalHealth; i = i + 0.1) {
curHealth = curHealth + 0.1;
System.out.println("health: " + curHealth);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但问题是java经历了这么快,它在游戏开始前从0到20.如何在不降低整个游戏速度的情况下减慢recoverHealth()方法,如Thread.sleep不起作用..
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?