这感觉就像一个初学问题,有一个非常明显的答案,但我无法弄清楚我的生活.我在下面尝试创建一个新元素并将其添加到正文中有什么问题?
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) 我使用以下代码生成从0到15的随机数.我使用函数random()生成唯一的数字我调用这样的函数
cat=random();
Run Code Online (Sandbox Code Playgroud)
我将随机数保存在数组r []中.并检查新生成的数字是否在数组中.如果发生重复,我再次调用random()函数.我使用警报只是检查它是否正常工作
function random(){
var ran,max=0,min=0;
max=r.length;
alert(max);
if (max>15)
alert("no more space");
ran=Math.floor(Math.random() * 15) + 0;
for (i=0;i<max;i++)
if (ran==r[i])
min++;
if (min>0){
alert("calling");
random(); //return in here
}else{
i=parseInt(max);
r[i]=ran;
return(ran);
alert(ran);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当复制发生时函数内的变量返回可以有人帮助解决这个问题.
我有以下代码:
var a=sessionStorage.getItem("Token");
alert(a==null);
Run Code Online (Sandbox Code Playgroud)
返回的值是null(如果我alert(a)显示null).问题是alert(a==null)firefox上的显示为TRUE,safari和chrome上的显示为FALSE.WTH?我尝试a===null过同样的结果以及!a.
我做错了什么或者我不知道什么?
谢谢你的帮助.
我的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) 这就是我所拥有的,这会导致错误:
for (var x = 0; x < 10; x++){
$('.wrapper ul').append('<li>Root Option 'x'</li>');
};
Run Code Online (Sandbox Code Playgroud) Object.prototype.jack = {};
var a = [1,2,3];
for(var number in a){
alert(number);
}
Run Code Online (Sandbox Code Playgroud)
谁能告诉我为什么"杰克"这个词跳出警报框?
非常感谢你!