我正在写一份注册表并尝试进行一些验证。当我的验证按钮位于内部时,我遇到了同样的问题,<form>但是为了解决这个问题,我只是将其移出,因为我猜测该按钮导致表单刷新。然而现在在“ValidateForm()”函数中插入多个 if 语句后,此错误消息似乎又回来了。
错误:未捕获 TypeError:Forename.focus 不是
ValidateForm(登录表单 Complex.html?Forename=&Surname=&Username=&Password=&Email=:79)处的函数
,位于 HTMLButtonElement.onclick(登录表单 Complex.html?Forename=&Surname=&Username) =&密码=&电子邮件=:63)**
function ValidateForm() {
var Forename = document.getElementById("Forename").value;
var Surname = document.getElementById("Surname").value;
var Username = document.getElementById("Username").value;
var Password = document.getElementById("Password").value;
var Email = document.getElementById("Email").value;
var Errors = 0
if (Forename == "") {
document.LoginForm.Forename.focus();
Forename.focus();
Errors = Errors + 1
}
if (Surname == "") {
document.LoginForm.Forename.focus();
Surname.focus();
Errors = Errors + 1
}
if (Username == "") {
document.LoginForm.Forename.focus();
Username.focus();
Errors = Errors + 1
} …Run Code Online (Sandbox Code Playgroud)我想,如果我选择"哺乳动物",动物选择选项只显示值为1的选项data-animal_class.
我知道如何获得哺乳动物的价值,但我对如何使用过滤器感到困惑
这是我的代码:
$('#class').on('change', function(e) {
e.preventDefault();
var animal = $(this).val();
console.log(animal);
})Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="class">
<option value=""></option>
<option value="1">Mammals</option>
<option value="2">Birds</option>
<option value="3">Reptiles</option>
</select>
<select id="animals">
<option value=""></option>
<option value="11" data-animal_class="1">Cow</option>
<option value="12" data-animal_class="1">Sheep</option>
<option value="13" data-animal_class="1">Bear</option>
<option value="21" data-animal_class="2">Parrot</option>
<option value="22" data-animal_class="2">Pigeons</option>
<option value="23" data-animal_class="2">Bear</option>
<option value="31" data-animal_class="3">Crocodile</option>
<option value="32" data-animal_class="3">Lizard</option>
<option value="33" data-animal_class="3">Turtle</option>
</select>Run Code Online (Sandbox Code Playgroud)
如何连接两个数组,其中一个也是数组。看起来像这样
let stat = [
["completed", "0", "0", "0"],
["due", "1", "2", "2"],
["warning", "0", "0", "0"]
]
let val = [
[0, 0, 0],
[1, 2, 2],
[0, 0, 0]
]
var arr = [];
for (var i = 0; i < stat.length; i++) {
var temp = [stat[i][0].concat([val[i]])];
arr.push(temp);
}
console.log(arr)Run Code Online (Sandbox Code Playgroud)
当console.log时,它将打印出:
["Completed0,0,0"]
["Due1,2,2"]
["Warning0,0,0"]
Run Code Online (Sandbox Code Playgroud)
我希望结果看起来像这样:
["Completed", 0, 0, 0]
["Due", 1, 2, 2]
["Warning", 0, 0, 0]
Run Code Online (Sandbox Code Playgroud)
我如何获得这样的新阵列?谢谢!
一直在尝试做以下事情:
我有一系列对象,
var arr = [
{ key: "aabFaa", text: "aabFaa" ,field: "firstName",checked: true},
{ key: "aAaaaa", text: "aAaaaa", field: "firstName", checked: true },
];
Run Code Online (Sandbox Code Playgroud)
想要从中获取“文本”和“字段”并形成一个新的对象数组,如下所示:
result = [ { "field" : "firstName" , value : "aabFaa" , type :"add"},
{ "field" : "firstName" , value : "aAaaaa" , type: "add"}
]
Run Code Online (Sandbox Code Playgroud)
这里的类型是硬编码的,其余部分是从“arr”中获取的
有什么更简单的方法可以做到这一点?
已经尝试过这个:
var arr = [
{ key: "aabFaa", text: "aabFaa" ,field: "firstName",checked: true},
{ key: "aAaaaa", text: "aAaaaa", field: "firstName", checked: true },
];
Run Code Online (Sandbox Code Playgroud)
但这必须写成多行才能获得所需的属性。有更简单的方法吗?
我想知道是否有人能够帮助弄清楚如何使用 cloudflare 工作人员将帖子正文传递到另一个端点?我正在尝试将传入的请求发布到 url。
const url = 'https://webhook.site/#!/b2f75ce2-7b9e-479a-b6f0-8934a89a3f3d'
const body = {
results: ['default data to send'],
errors: null,
msg: 'I sent this to the fetch',
}
/**
* gatherResponse awaits and returns a response body as a string.
* Use await gatherResponse(..) in an async function to get the response body
* @param {Response} response
*/
async function gatherResponse(response) {
const { headers } = response
const contentType = headers.get('content-type') || ''
if (contentType.includes('application/json')) {
return JSON.stringify(await response.json())
} …Run Code Online (Sandbox Code Playgroud) 我function error()的工作不是从 php 代码调用。所以请帮助我解决这个问题。在 php 代码之外调用时,fucntion 可以正常工作。但是在 php 代码中调用时没有显示输出。
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" href="css/design.css">
<script type="text/JavaScript">
function error(){
document.getElementById("wrong-attempt").innerHTML="Wrong Username Or Password";
}
</script>
<?php
if(isset($_POST['submit'])){
echo '<script> error(); </script>';
}
?>
</head>
<body background="pics/background.jpg">
<div class="wrapper">
<center>
<div class="form-wrapper">
<form action="index.php" method="POST">
<div>
</div>
<h1>User Login</h1>
<div>
<img src="pics/login.png" width="100" height="100"/>
</div>
<div>
<input name="ID" placeholder=" Username" type="text" required="true"/></br>
<input name="pass" placeholder=" Password" type="password" required="true"></br>
<input type="image" src="pics/loginb.png" name="submit" value="Login" width="100"/>
</div>
</form>
<div id="wrong-attempt"> …Run Code Online (Sandbox Code Playgroud) 我有问题,DIV内的照片没有显示.由于我使用的是砌体网格,而网站就像是Pinterest,我不想限制图像或内部的高度,所以我把auto,但是当我把auto,或100%,图像没有显示时,我的代码在下面.
.inner {
background-color: rgb(255, 255, 255);
padding-bottom: 40px;
height:auto;
position: relative;
overflow: hidden;
border: 2px solid #ECECEC;
margin-bottom: 30px;
}
.image-box {
position:relative;
height: auto;
width: 100%;
padding-right: 0px;
padding-left: 0px;
background-position: center;
background-color: #4D4E56;
}
.image-box .img{
width: 100%;
display: block;
float: left;
background-repeat: no-repeat;
background-size: cover;
}Run Code Online (Sandbox Code Playgroud)
<div class="inner">
<a href="{{ link }}"><div class="image-box" style="background-image:url(http://placehold.it/350x550)"></div></a>
</div>Run Code Online (Sandbox Code Playgroud)
我是一个JS新手试图从一组json地图中提取一些值.地图是这样的:
var tags = [{
Key: 'backup',
Value: 'true'
},
{
Key: 'Name',
Value: 'sdlc-root'
}
]
// Here is my first attempt:
var volName = tags.filter(function(item) {
return item.Key === 'Name';
})
.map(result => {
return result.Value;
});
console.log(volName);Run Code Online (Sandbox Code Playgroud)
结果是: [ 'sdlc-root' ] ,但我只需要String值.
我现在采取的临时解决方案是:
var volName = tags.filter(function(item) { return item.Key === 'Name'; })
.map(result => { return result.Value; })**[0]**;
console.log(volName);
Run Code Online (Sandbox Code Playgroud)
结果是: sdlc-root
我讨厌我的临时解决方案,并希望听到一些改进建议或经验丰富的开发人员的替代方案
我正在尝试生成随机数,并在每次页面加载时将其显示在div中.问题是它不起作用,并且最重要的是浏览器中的js控制台与某些令牌有问题.我认为他们是对的(下面的代码),但即使我试图改变它们,它仍然说同样的事情.你知道问题出在哪里吗?谢谢!
window.addEventListener('load', function() {
function generateRandomNumber();
document.querySelector("#text").textContent = "The number is " + rnum + ".";
})
function generateRandomNumber() {
var rnum = (Math.floor(Math.random() * 20) + 1);
return rnum;
}Run Code Online (Sandbox Code Playgroud)
<div id="count">
<div id="text">
</div>
</div>Run Code Online (Sandbox Code Playgroud)
我有以下代码:
请参阅此处的 codepen 示例:https://codepen.io/Rubenkretek/pen/VwYQVgO ?editors=1111
预期结果:单击“+”按钮时输入字段会增加 1。
实际结果:输入没有变化,出现以下错误:
类型错误:selectedInput.stepUp 不是函数
$(function() {
$('<span class="add" uk-icon="plus">+</span>').insertAfter('.product-container .product-quantity input');
$('<span class="sub" uk-icon="minus">-</span>').insertBefore('.product-container .product-quantity input');
$('.add').click(function() {
var selectedInput = $(this).prev('input');
if (selectedInput.val() < 10) {
console.log("value is less than 10");
$('.add').click(function() {
selectedInput.stepUp(1);
});
}
});
});Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="product-container">
<div class="product-info">
<h2>Product name</h2>
</div>
<div class="product-quantity">
<input type="number"></input>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
javascript ×7
html ×3
css ×2
jquery ×2
arrays ×1
css3 ×1
dom ×1
ecmascript-6 ×1
forms ×1
php ×1