为什么document.body.getElementById(idOfElem)和document.body.getElementsByName(nameOfElem)不工作?
和
为什么document.body.getElementByTagName(tagOfElem)和document.body.getElementByClassName(classOfElem)工作?
使用第一个时,浏览器抛出此错误:
类型错误:document.body.getElementById 不是函数[了解更多]
如何"e"将"arr"中的元素替换为change0?
的arr阵列将是由用户的输入和我需要改变它没有办法预测哪个元素将是"e".
var arr = [ "a", "b", "c", "d", "e", "f", "g", "h", "e", "j", "e"];
var change0 = 2
var change1 = 1
document.write(arr);
Run Code Online (Sandbox Code Playgroud) 我试图深度克隆一个对象,用k = JSON.parse(JSON.stringify(a))说"a".我使用stringify方式很重要,因为我试图将对象保存到文件中然后从中加载.
我偶然发现了克隆对象的引用问题,如下所示:
var obj={};
obj.importantProperty={s:2};
obj.c=obj.importantProperty;
obj.d=obj.importantProperty;
console.log( obj.c === obj.d ); // Returns true
var cloned = JSON.parse(JSON.stringify(obj));
console.log( cloned.c === cloned.d ); // Returns falseRun Code Online (Sandbox Code Playgroud)
在此先感谢任何帮助我的人:)
这是我的代码:
function permAlone(string) {
if (string.length < 2) return string; // This is our break condition
var permutations = []; // This array will hold our permutations
for (var i = 0; i < string.length; i++) {
var character = string[i];
// Cause we don't want any duplicates:
if (string.indexOf(character) != i) // if char was used already
continue; // skip it this time
var remainingString = string.slice(0, i) + string.slice(i + 1, string.length); //Note: you can concat Strings via …Run Code Online (Sandbox Code Playgroud)我可以改变:
成:
不使用照片编辑器
这是CSS和HTML代码
我无法上传徽标,因为我应该至少有10个声望才能发布超过2个链接,所以我可能会将其插入另一个评论中
header {
background-color: rgba(255, 255, 255, 0.9);
height: 50px;
display: flex;
flex-direction: row;
align-items: center;
position: fixed;
width: 100%;
box-sizing: border-box;
top: 0;
left: 0;
z-index: 2;
}
header .logo {
position: fixed;
left: 50%;
top: 13px;
display: inline-block;
}
.background-image {
position: fixed;
left: 0;
top: 0;
z-index: 1;
width: 100%;
height: 100%;
background: #fff url('https://upload.wikimedia.org/wikipedia/commons/thumb/e/e5/%D0%94%D0%B7%D0%B5%D0%BC%D0%B1%D1%80%D0%BE%D0%BD%D1%8F._%D0%9F%D0%B5%D1%80%D0%B2%D1%8B%D0%B5_%D0%BB%D1%83%D1%87%D0%B8_%D1%81%D0%BE%D0%BB%D0%BD%D1%86%D0%B0.jpg/800px-%D0%94%D0%B7%D0%B5%D0%BC%D0%B1%D1%80%D0%BE%D0%BD%D1%8F._%D0%9F%D0%B5%D1%80%D0%B2%D1%8B%D0%B5_%D0%BB%D1%83%D1%87%D0%B8_%D1%81%D0%BE%D0%BB%D0%BD%D1%86%D0%B0.jpg') no-repeat center center;
background-size: 100%;
}Run Code Online (Sandbox Code Playgroud)
<body>
<header>
<div class="header-section logo">
<a href="/">
<img src="http://i.imgur.com/IB1gfZB.png" alt="...">
</a>
</div> …Run Code Online (Sandbox Code Playgroud)我发现ES2015类阻止了他们原型的设置(重新定义).
人们常说,ES2015类只是ES5构造函数和基于原型的继承之上的"语法糖".
但这是行为上的差异......
这种行为是ES2015规范的一部分吗?我没有找到任何关于这个的文件......
以下示例说明了不同之处:
function Pet() {}
Pet.prototype.eat = () => {
console.log('Pet is eating ...');
}
Pet.prototype = {eat: function(){console.log('Pet is REALLY eating ...')}};
const pet = new Pet();
pet.eat(); // -> Pet is REALLY eating ...
console.log(Object.getOwnPropertyDescriptor(Pet, 'prototype'));Run Code Online (Sandbox Code Playgroud)
=>重新定义宠物作品的原型
class Pet {
eat() {
console.log('Pet is eating ...');
}
}
Pet.prototype = {eat: function(){console.log('Pet is REALLY eating ...')}};
const pet = new Pet();
pet.eat(); // -> Pet is eating ...
console.log(Object.getOwnPropertyDescriptor(Pet, 'prototype'));Run Code Online (Sandbox Code Playgroud)
=>重新定义Pet的原型不起作用
任何指向此行为的文档的指针将不胜感激...
您能解释一下下面的代码有什么问题吗?
function box (width, height, color) {
this.width=width;
this.height=height;
this.color=color;
this.style.width=width;
this.style.height=height;
this.style.backgroundColor=color;
}
var box1 = new box (100, 100, 'red');
document.body.appendChild(box1);
Run Code Online (Sandbox Code Playgroud) 我对node和mongoose有点陌生,我正在尝试删除集合中的所有文档。我正在使用此代码:
app.delete('/accounts', function deleteAccount(req, res, next){
Account.remove({}, {multi:true});
res.json({
message: 'Accounts Deleted!'
});
});
Run Code Online (Sandbox Code Playgroud)
问题是,当我对此方法发出API请求时,它会开始处理并且不会停止,除非我中止它。该代码删除了我的收藏夹中的所有文档,但是这样做却出错。这是它引发的错误:
events.js:141
投掷者 //未处理的“错误”事件^
TypeError:callback.apply不是函数
我希望我的代码能正常工作而不会出现此错误,并且我不希望我的请求在处理请求时挂起。欢迎任何建议。
我需要这方面的帮助,我需要按 id 和 sum 分组,但我需要为每个结果创建一个新对象
let data =[
{"id":"2018", "name":"test", "total":1200},
{"id":"2019", "name":"wath", "total":1500},
{"id":"2019", "name":"wath", "total":1800},
{"id":"2020", "name":"zooi", "total":1000},
]
Run Code Online (Sandbox Code Playgroud)
我有这段代码只返回一个带有结果的对象
let result = data.reduce(function (r, o) {
(r[o.id])?
r[o.id] += o.total:
r[o.id] = o.total;
return r;
});
Run Code Online (Sandbox Code Playgroud)
但我需要一些这样的
[
{"id":"2018", "name":"test", "total":1200},
{"id":"2019", "name":"wath", "total":2300},
{"id":"2020", "name":"zooi", "total":1000},
]
Run Code Online (Sandbox Code Playgroud)
有什么建议吗,谢谢
使用一系列对象,例如:
const arr = [
{name: "qewregf dqewafs", value: "qewregf dqewafs answer", count: 2},
{name: "survey with select", value: "survey with select answer", count: 2},
{name: "werasd", value: "Donald", count: 1},
{name: "werasd", value: "Jim", count: 1}
];
Run Code Online (Sandbox Code Playgroud)
我正在尝试减少name键的匹配值上的数组,并实现所需的输出,例如:
desiredOutput = [
{name: "qewregf dqewafs", data: [{value: "qewregf dqewafs answer", count: 2}]},
{name: "survey with select", data: [{value: "survey with select answer", count: 2}]},
{name: "werasd", data: [{value: "Donald", count: 1}, {value: "Jim", count: 1}]}
]
Run Code Online (Sandbox Code Playgroud)
这种尝试减少了数组,但是我不知道如何在不覆盖的情况下合并嵌套值。