我有以下代码(我使用的是jQquery库):
var obj = {};
var objstring = '{"one":"one","two":"two","three":"three"}'
// first console output
console.log(objstring);
var jsonobj = $.parseJSON(objstring);
// second console output
console.log(jsonobj);
obj.key = jsonobj;
obj.key.test = "why does this affect jsonobj? (even in the second console output)";
// third console output
console.log(jsonobj);
Run Code Online (Sandbox Code Playgroud)
我的问题:当我做obj.key = jsonobj并且我在新的obj.key中更改值时.为什么jsonobj中的值也会改变?我怎么能避免这种情况?(我想要一个新的jsonobj"副本").
我做了这个测试用例:http://jsfiddle.net/WSgVz/
我有一堆 webpack 入口点配置如下:
\n\nmodule.exports = {\n entry: {\n pageOne: \'./src/pageOne.js\xe2\x80\x99,\n pageTwo: \'./src/pageTwo.js\xe2\x80\x99,\n pageThree: \'./src/pageThree.js\xe2\x80\x99\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n这些条目本身导入各种模块。\n例如 pageOne.js导入module1.js
\n\n我还使用骨架加载器来处理原始 javascript 内容(pageOne.js 、 pageTwo.js、 \xe2\x80\xa6 )
\n\n此加载器回调函数\xc2\xb4s \xe2\x80\x9cthis\xe2\x80\x9d 指的是\xe2\x80\x9cloader 上下文\xe2\x80\x9d
\n\n我的问题:\n现在我在回调中拥有文件内容(例如module1.js )及其相应的加载器上下文(通过此)。但我需要知道module1.js的(原始/父)条目名称。因此,对于module1.js,它应该告诉我它是原始pageOne条目名称的一部分。那可能吗?
\n我有这个:
<div class="selection">
<a class="current" href="#">1</a>
<div class="class">text</div>
<a href="#">2</a>
<div class="class">text</div>
<a href="#">4</a>
<div class="class">text</div>
<a href="#">5</a>
</div>
Run Code Online (Sandbox Code Playgroud)
我想在a.current之后选择下一个元素.我做到了这一点,但它做得很好.
...
$(".selection a.current").next("a").hide();
Run Code Online (Sandbox Code Playgroud)
我也试过了
$(".selection").children("a.current").next("a").hide();
Run Code Online (Sandbox Code Playgroud)
...不是所有的内部.selection兄弟姐妹,因此可以使用next()选择器访问?我想知道,因为当我删除它们之间的div元素时它会起作用.
如果有人知道为什么这不起作用会很好;).
我必须承认,我不是数学专家,这就是为什么我无法解决以下问题让我满意.
我有一个数字,比如i = 0.我有一个函数,每次调用增加i然后再调用自己,增加另一个时间和另一个和另一个...当达到100时,我希望它倒数到0然后再次上升,有点像一个强项我像电梯一样上下循环.什么是优雅的解决方案?
到目前为止我的解
var countingUp = true;
var i = 0;
function count() {
if(i < 100 && countingUp) {i+=1}
if(i > 1 && !countingUp) {i-=1}
if(i===100) {countingUp=false;}
if(i===1) {countingUp=true;}
count()
}
count()
Run Code Online (Sandbox Code Playgroud)
我正在寻找更短的东西.
让我们说:
var array = [0,1,2,3,4,5,6,7,8,9]
Run Code Online (Sandbox Code Playgroud)
我定义:
var itemsToExtract = 5
var startindex = 7
var direction = "forward"
Run Code Online (Sandbox Code Playgroud)
我希望能够做到:
array.someMethod(startindex, itemsToExtract, direction)
Run Code Online (Sandbox Code Playgroud)
得到
[7,8,9,0,1]
Run Code Online (Sandbox Code Playgroud)
如果我将方向设置为"向后"(从右到左切片),我也希望它向后工作.
我不是太懒了,已经尝试了一些东西,请看这里:http://jsfiddle.net/MkNrr/
我正在寻找"更整洁"的东西,如果有的话,这个方法也有名称,这是一个已知的问题吗?
背景:我正在尝试构建一个顺序的预图像加载器(一个图像(src)加载另一个)以用于图像库.也许甚至这样的图书馆已经存在?
向下滚动.parent
div时,由于,您应该在底部看到其红色背景padding-bottom
。这在Chrome中有效,但在Safari和Firefox中无效。
.container {
display: flex;
width: 200px;
height: 500px;
}
.parent {
display: flex;
flex-direction: column;
background: red;
padding-top: 20px;
padding-bottom: 20px;
overflow: auto;
flex: 1;
}
.child {
flex: 1 0 100px;
background: green;
border: 1px solid blue;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="parent">
<div class="child">
child
</div>
<div class="child">
child
</div>
<div class="child">
child
</div>
<div class="child">
child
</div>
<div class="child">
child
</div>
<div class="child">
child
</div>
<div class="child">
child
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
codepen:http …
我正在努力让最简单的css悬停伪类工作.有谁知道为什么以下不起作用?
css
#hidden {display:none;}
#show:hover #hidden{display:block;}
Run Code Online (Sandbox Code Playgroud)
HTML
<a href="#" id="show">show</a>
<div id="hidden">here i am</div>
Run Code Online (Sandbox Code Playgroud)
我真的觉得愚蠢地问这么简单的问题,我做了很多次,但是无法弄清楚为什么这不起作用.
我正在运行一个简单的:
window.location.hash = "hash";
Run Code Online (Sandbox Code Playgroud)
在页面加载后立即在 url 中添加哈希值。我明白了,mySite.com/aPage#hash。当我单击后退按钮时,我希望 url 更改回 mySite.com/aPage,而无需任何实际加载/返回。相反,我被带回到 mySite.com/aPage 之前的历史记录条目。
当我在用户触发的点击事件回调中调用 window.location.hash 时,它效果很好。
我创建了一个测试:http://jsbin.com/idukiz/1/ 查看代码:http://jsbin.com/idukiz/1/edit
只有 setTimeout 函数中添加的最后一个哈希的行为符合我的预期。有什么想法如何让它在没有 setTimeout 的情况下工作吗?
在 Safari 版本 7.0.1 和 IE8 中会发生以下情况。
重现问题的步骤: http: //goo.gl/lP3Ky1
问题:关闭弹出菜单后,该行的悬停状态仍然存在,并且无论鼠标位于何处,它都不会消失,直到您再次将鼠标悬停在其上。
预期的行为是什么?关闭弹出菜单后,该行的悬停状态应该消失。
有人知道 Safari 7.0.1 版和 IE8 的修复程序吗?我可以使用一些手动方式来“取消触发”CSS 悬停状态。
我有一个带有border-radius的div.在IE10和IE11中显示某种类型的fragemnts.
原因是什么?我们如何解决这个问题?
使用IE10或IE11访问此站点以查看效果:http: //css3pie.com/demos/border-radius
访问小提琴:http://goo.gl/pKLe89