如何在最后一个函数执行后保持代码 运行,我是这个新手,如果没有意义
how to keep code running after last function executed, im a newbie to this sorry if doesnt make sense
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Assignment 3 </title>
<script src="../JAVASCRIPT/question2.js" defer></script>
</head>
<body>
<h1>Shopping List</h1>
<input type="text" id="firstname" >
<input type='submit' onclick='changeText2()' value='Add Item' />
<input type="text" id="delitem" >
<input type='button' onclick='getNames()' value='Delete Item' />
<br><ol id="demo"></ol>
<input type='button' onclick='delevrytin()' id="evetang" value='Delete all' />
</body>
</html>
var list = document.getElementById('demo'); //demo is the organised list
//this function is for the add button
function changeText2() {
var firstname = document.getElementById("firstname").value
// the if satatement alerts if input is blank
if ((firstname == "") || (firstname == null)) {
alert("can't be blank");
return; //alerts if noting is inputed and add is clicked
}
//creates a list item
var entry = document.createElement('li');
entry.appendChild(document.createTextNode(firstname));
list.appendChild(entry);
document.getElementById('firstname').value = ''; //clears textbox
}
// this function clears specific item starting from 0
var list = document.getElementById('demo');
function getNames()
{
var remov = document.getElementById('delitem').value;
list.removeChild(list.childNodes[remov]);
}
//delete all button
function delevrytin()
{
document.getElementById('demo').remove;
}
我的问题是点击 delevrytin 函数
它可以工作,但会阻止其他功能工作。
谁能解决我的问题强调文本 将不胜感激
一切都很好,现在对我来说 运行
几个变量和 id 已更改
var list = document.getElementById('org'); // var for the organized list gets it by id
//this function is for the add button
function changeText2() {
var firstitem = document.getElementById("firstitem").value
// the if statement alerts if input is blank
if ((firstitem == "") || (firstitem == null)) {
alert("can't be blank");
return; //alerts if noting is inputed and add is clicked
}
//creates a list item
var entry = document.createElement('li');
entry.appendChild(document.createTextNode(firstitem));
list.appendChild(entry);
document.getElementById('firstitem').value = ''; //clears textbox
}
// this function clears specific item starting from 0
function getNames()
{ // creates a variable and assigns it to the delitem input
var remov = document.getElementById('delitem').value;
//remove - 1 lets you delete the list item but the number beside it
list.removeChild(list.childNodes[remov = remov - 1]);
}
//delete all button
function delevrytin()
{ //if there is a child node remove it
while (list.firstChild) {
list.removeChild(list.firstChild);
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Assignment 3 </title>
<script src="../JAVASCRIPT/question2.js" defer></script>
</head>
<body>
<h1>Shopping List</h1>
<input type="text" id="firstname" >
<input type='submit' onclick='changeText2()' value='Add Item' />
<input type="text" id="delitem" >
<input type='button' onclick='getNames()' value='Delete Item' />
<br><ol id="demo"></ol>
<input type='button' onclick='delevrytin()' id="evetang" value='Delete all' />
</body>
</html>
var list = document.getElementById('demo'); //demo is the organised list
//this function is for the add button
function changeText2() {
var firstname = document.getElementById("firstname").value
// the if satatement alerts if input is blank
if ((firstname == "") || (firstname == null)) {
alert("can't be blank");
return; //alerts if noting is inputed and add is clicked
}
//creates a list item
var entry = document.createElement('li');
entry.appendChild(document.createTextNode(firstname));
list.appendChild(entry);
document.getElementById('firstname').value = ''; //clears textbox
}
// this function clears specific item starting from 0
var list = document.getElementById('demo');
function getNames()
{
var remov = document.getElementById('delitem').value;
list.removeChild(list.childNodes[remov]);
}
//delete all button
function delevrytin()
{
document.getElementById('demo').remove;
}
我的问题是点击 delevrytin 函数 它可以工作,但会阻止其他功能工作。 谁能解决我的问题强调文本 将不胜感激
一切都很好,现在对我来说 运行 几个变量和 id 已更改
var list = document.getElementById('org'); // var for the organized list gets it by id
//this function is for the add button
function changeText2() {
var firstitem = document.getElementById("firstitem").value
// the if statement alerts if input is blank
if ((firstitem == "") || (firstitem == null)) {
alert("can't be blank");
return; //alerts if noting is inputed and add is clicked
}
//creates a list item
var entry = document.createElement('li');
entry.appendChild(document.createTextNode(firstitem));
list.appendChild(entry);
document.getElementById('firstitem').value = ''; //clears textbox
}
// this function clears specific item starting from 0
function getNames()
{ // creates a variable and assigns it to the delitem input
var remov = document.getElementById('delitem').value;
//remove - 1 lets you delete the list item but the number beside it
list.removeChild(list.childNodes[remov = remov - 1]);
}
//delete all button
function delevrytin()
{ //if there is a child node remove it
while (list.firstChild) {
list.removeChild(list.firstChild);
}
}