我有两个js文件,都由一个HTML文件调用.
<script type="text/javascript" src="scripts/levelmovement.js"></script>
<script type="text/javascript" src="scripts/generation.js"></script>
Run Code Online (Sandbox Code Playgroud)
levelmovement.js的一部分:
function moveLevel(){
if(firstreset == true){
resetTime();
}
var time2 = new Date();
var millis2 = time2.getTime();
var millis3 = millis2 - millis1;
poschange = Math.floor(millis3 / 5);
for(i = 0; i < chunkpos.length; i++){
temppos[i] = chunkpos[i] - poschange;
if(temppos[i] <= -150){
temppos[i] += 1200;
generate(i);
}
pos = temppos[i];
document.getElementById('chunk' + i).setAttribute('style','left: ' + pos + 'px;');
}
}
Run Code Online (Sandbox Code Playgroud)
函数"moveLevel()"的调用方式如下:
window.onload = function(){
gameLoop();
}
function gameLoop(){
if(currentscreen == 'playing'){
moveLevel(); …Run Code Online (Sandbox Code Playgroud) 我想通过以下单击绑定方法传递特定上下文:
$(document).ready(function(){
var o = {
name : 'I\'m object O'
};
$('#my-button').click(function(){
alert(this.name);
}.call(o));
});
Run Code Online (Sandbox Code Playgroud)
问题是,只要页面加载就会触发此操作.有没有办法可以将上下文绑定到click处理程序的匿名函数,并且只有在触发click事件时才触发它?你也可以解释为什么它是在页面加载而不是点击事件上触发的.
我认为$(document).ready(...)中的脚本总是在加载DOM后执行.因此,如果一个$(document.ready(...)进入头部或正文中就没关系.但是,下面的代码不会像我想要的那样在屏幕上生成"苹果".如果我找到页面底部的giveApples()函数,它可以工作.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(giveApples());
function giveApples() {
$("#appleTree").html("apples");
}
</script>
</head>
<body>
<div id="appleTree"></div>
</body>
<script>
//$(document).ready(giveApples());
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
任何人都可以请更正我对DOM,页面加载,脚本标记位置,(文档).ready()或其他任何导致此问题的误解吗?我还是网络编程的新手.
我已经搜索过使用C语言捕获/播放音频的方法,但我没有找到任何有用的东西.有没有这样做的方法,或者我将不得不使用其他语言,如C++,C#或Java?
我有一个外部文件contacts.json.我如何将其转换为javascript数组?
这是contacts.json内容:
{
"ppl1":{
"Name":"Jhon",
"Surname":"Kenneth",
"mobile":329129293,
"email":"jhon@gmail.com"
},
"ppl2":{
"Name":"Thor",
"Surname":"zvalk",
"mobile":349229293,
"email":"thor@gmail.com"
},
"ppl3":{
"Name":"Mila",
"Surname":"Kvuls",
"mobile":329121293,
"email":"mila@gmail.com"
}
}
Run Code Online (Sandbox Code Playgroud) 在mysql中创建触发器时我得到错误1046.我的查询是:
CREATE TABLE test.Employee(
id int,
first_name VARCHAR(30),
last_name VARCHAR(15),
start_date DATE,
end_date DATE,
city VARCHAR(10),
description VARCHAR(15)
);
CREATE TABLE test.Employee_log(
id int,
first_name varchar(50),
last_name varchar(50),
start_date date,
end_date date,
city varchar(50),
description varchar(50),
Lasinserted Time
);
Run Code Online (Sandbox Code Playgroud)
当我在线下执行时它会给出错误:
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END$$
delimiter' at line 1
(16 ms taken)
delimiter $$
CREATE …Run Code Online (Sandbox Code Playgroud) 这感觉就像一个初学问题,有一个非常明显的答案,但我无法弄清楚我的生活.我在下面尝试创建一个新元素并将其添加到正文中有什么问题?
var newDiv = document.createElement("div");
newDiv.setAttribute("id", "popup");
newDiv.setAttribute("width", "400px");
newDiv.setAttribute("height", "400px");
newDiv.setAttribute("backgroundColor", "red");
document.getElementsByTagName("body")[0].appendChild(newDiv);
newDiv.style.position = "absolute";
newDiv.style.left = "25px";
newDiv.style.top = "25px";
Run Code Online (Sandbox Code Playgroud) 我试图添加一个链接到页面我不能直接访问HTML,除了页脚.使用Javascript,我试图使用该createElement()方法.我已成功使用相同的过程link在标题中创建元素.
function createForgotPasswordLink(){
var pwlink=document.createElement("a")
pwlink.setAttribute("id", "forgotPssLink")
pwlink.setAttribute("href", "http://www.mysite.com/page.aspx")
pwlink.innerHTML("Forgot Password?")
document.getElementsByTagName("body")[0].appendChild(pwlink)
}
createForgotPasswordLink();
Run Code Online (Sandbox Code Playgroud)
两个脚本之间的唯一区别是,制作时link元,我appendChild()就head不会body,我没有设置innerHTML的的link元素作为我在上面已经做了a元素.出于某种原因,上述代码不起作用.即使在删除第5行之后.
我的html中的图像标签具有空的src属性.这会导致不同浏览器中的错误.我想动态删除所有具有空src的图像标记
HTML:
<div class="newsroom-item">
<article>
<figure>
<a href="/content/NewsRoom/648408.html">
<img src="" alt="" data-blog="" data-list="">
</a>
</figure>
</article>
</div>
Run Code Online (Sandbox Code Playgroud)
我需要有关Javascript的帮助:
var figure = $('.newsarticle-list #newsarticlelist .newsroom-item figure a img');
$("figure[src='']").each(function () {
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试将以下javascript转换为java
var lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R) +
Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng) );
var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1),
Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2));
Run Code Online (Sandbox Code Playgroud)
这一切都相当简单,除了我不确定cos(lat1)之后的逗号是什么?我在javascript中读到它用于将昏迷后的值分配给变量,同时仍然在评估第一个表达式,尽管在上面的代码中,逗号之前的表达式没有存储?
有关将此转换为java或了解逗号的功能的任何帮助吗?
原始数学公式也有逗号
?2 = asin( sin(?1)*cos(d/R) + cos(?1)*sin(d/R)*cos(?) )
?2 = ?1 + atan2( sin(?)*sin(d/R)*cos(?1), cos(d/R)?sin(?1)*sin(?2) )
Run Code Online (Sandbox Code Playgroud)