我正在尝试硬编码一种登录系统,因为我试图有两个输入并点击检查这些值是否与数组中的值相匹配,该数组有两个对象可用于两个答案......
好吧,我不能让它工作,所有的suden我的变量都无法识别,整体代码已经变成了kaput ...这是笔
提前致谢!
到目前为止的代码顺便说一句
$(".submit").click(function() {
//bidimensional array
var data = [{
user: "cinco",
pw: "king"
}, {
user: "manco",
pw: "wawa"
}];
var name = $(".name").val();
var pass = $(".pw").val();
if (data.user.includes(name) && data.pw.includes(pass)) {
$(".check-input").addClass('valid');
} else {
$(".check-input").addClass('invalid');
}
});
$(".input").focus(function() {
$(".check-input").removeClass("valid");
$(".check-input").removeClass("invalid");
});
Run Code Online (Sandbox Code Playgroud) 我尝试使用 JSONView 显示此代码,但从 api 回调函数内部调用数据时不会显示,但在回调外部时会显示非 api 数据。
// Call FreeGeoIP API to get browser IP address
$.getJSON('https://freegeoip.net/json/', function(data) {
var ipaddress = data.ip;
// Get browser language
var language = window.navigator.language;
// Get software
var software = window.navigator.appVersion;
var regExp = /\(([^)]+)\)/;
software = regExp.exec(software)[1];
// Add data to obj
var obj = {
'ipaddress': ipaddress,
'language': language,
'software': software
};
// Write obj to document
$('body').html(JSON.stringify(obj));
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>Run Code Online (Sandbox Code Playgroud)
我希望在使用后distances.slice(),我会得到该数组的副本。但是当我更改新副本的元素时,它仍然会更改原始数组。为什么?
var distances = [
['-1', '10', '-1', '31'],
['10', '-1', '10', '-1'],
['-1', '-1', '-1', '10'],
['15', '6', '-1', '-1']
];
for (var i = 0; i < 4; i++) {
console.log(distances, 'distances pairstop');
var sampleDistance = distances.slice()
sampleDistance[0][2] = ['fooo']
}Run Code Online (Sandbox Code Playgroud)
为什么下面的代码块不输出字符串?
当我们传递num = 1时,我期待它应该显示abc.
我在这里缺少什么?
function repeatStringNumTimes(str, num) {
return Array(num).join(str);
}
console.log(repeatStringNumTimes("abc", 1));Run Code Online (Sandbox Code Playgroud)
在python中,我的数据框像:
date1 num
2017-03-02 8
2017-04-15 4
2017-06-30 1
Run Code Online (Sandbox Code Playgroud)
我想要这样的结果数据框(添加 date2 列):
date1 num date2
2017-03-02 8 2017-03-10
2017-04-15 4 2017-04-19
2017-06-30 1 2017-07-01
Run Code Online (Sandbox Code Playgroud)
我知道:df.date1 +pd.offsets.Day(x),但x不允许是系列。而且我知道apply()函数可能可以解决这个问题,但是我的数据帧的行数超过 10 亿。
那么该怎么办?
我有以下数组需要使用 .includes 来检查它们是否是重复或没有的对象。问题是它总是返回 false 所以我不确定是否有正确的方法或 .includes 不能以这种方式使用。
var array_rooms = [{
type: "Heritage",
n: 1
}, {
type: "Hanuono",
n: 1
}, {
type: "Bangon",
n: 1
}, {
type: "Heritage",
n: 1
}]
console.log(array_rooms.includes("Heritage"));
//should return trueRun Code Online (Sandbox Code Playgroud)
我浏览了下面的链接,了解单线程javascript及其异步性质
https://www.sohamkamani.com/blog/2016/03/14/wrapping-your-head-around-async-programming/
但是我仍然有一些问题,即javascript是单线程的,并且它总是以顺序方式向前移动,直到它完成执行.
每当我们调用具有回调函数时,该函数将在函数接收到响应后执行.在响应的等待时间内继续执行javascript代码.通过这种方式,执行顺序执行后如何在收到响应后恢复执行回调执行.这就像线程向后移动以进行回调执行.
执行线程应始终向前移动righy?
请澄清一下.
要点:单击按钮时,content-div旋转360度。但是,在第二次单击时,什么也没有发生。
我想要的是,每次单击按钮时,div元素都会旋转360度,就像第一次单击一样。
我找到了一些jQuery建议,但我希望通过使用JavaScript来完成。
var content = document.getElementById("content");
var btn = document.getElementById("btn");
btn.addEventListener("click", function() {
content.style = 'transform: rotate(' + 0 + '360deg)';
});Run Code Online (Sandbox Code Playgroud)
#content {
width: 100px;
height: 100px;
border-radius: 50%;
background: lightblue;
display: flex;
align-items: center;
justify-content: center;
transition: all 1s ease-in-out;
}
#btn {
width: 100px;
height: 50px;
background: grey;
display: flex;
align-items: center;
justify-content: center;
color: white;
text-decoration: none;
}
a {
color: white;
text-decoration: none;
}Run Code Online (Sandbox Code Playgroud)
<div id="content">
<p>It's spinning</p>
</div>
<div …Run Code Online (Sandbox Code Playgroud)I need help with array sum algorithm, sum of result array values is never greater then limit, I have provided input => output bellow
I have tried something like this but It doesn't work properly for all tests in example
input
.map((x, i) => input
.slice(0, i + 1)
.reduce((prev, cur) => prev + cur, 0) > limit ? Math.max((x - (input.reduce((prev, cur) => prev + cur, 0) - limit)), 0) : x)Run Code Online (Sandbox Code Playgroud)
Example tests:
limit = 500
[0] => …
我不希望在 else 条件下第二个元素为 null .. 我只是不想要第二个元素。如何解决这个问题?
var template = "";
var myArray = [
{ element : "header" },
template === 'foo' ? { element : "sidebar" } : null,
{ element : "footer" }
]
console.log(myArray)Run Code Online (Sandbox Code Playgroud)