Javascript创建一个对象来存储所有数据并显示信息

时间:2019-03-22 00:44:46

标签: javascript

我正在尝试创建一个“客户”对象,该对象将存储所有这些数据,然后将该信息显示为“客户订单”,类似于列出所有新信息。 我不知道是什么问题。 (很确定整个代码本身都搞砸了) 当我运行它时,它还会显示“ ReferenceError:未定义单击”的消息。 我不理解存储数据和将新信息显示为“客户订单”的概念。

这是我的JavaScript。

/*index.js*/

var objectarray = [];
function addToArray() {

  var customerobject = {
    name: "",
    address: "",
    postalcode: "",
    phone: "",
    email: ""
  }
  customerobject.name = document.getElementById("name").value;
  customerobject.address = document.getElementById("address").value;
  customerobject.postalcode = document.getElementById("postalcode").value;
  customerobject.phone = document.getElementById("phone").value;
  customerobject.email = document.getElementById("email").value;
  objectarray.push(customerobject);
  console.log(objectarray);

}
document.getElementById("buttonandchecks").addEventListener("click", clicked);


function clicked() {
  addToArray();
}
<input id="name" value="Jenna" />
<input id="address" value="840 9STREET" />
<input id="postalcode" value="T2P 2T4" />
<input id="phone" value="111-111-1111" />
<input id="email" value="Renee@gmail.com" />
<button id="clickMe">click me</button>



function buttonandchecks()

{

	//javascripts to get an output based on customer information

			

}

> ------------------------Below is my html------------------------
<!DOCTYPE html>
<html>
<head>
<link href="this.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="this.js">
</script>


</head>



<body>
<br>
<form name="information">
<table>
<tr><td>;	  First and Last Name :;</td><td><input type="name" id="nameid" size="25" maxlength="25" autofocus="yes" pattern="[a-zA-Z -]+$"></td></tr>
<tr><td>;	  Address :;</td><td><input type="address" id="addressid" size="25" maxlength="25" pattern="[a-zA-Z0-9]| |/|,|.|\|@|#|$|%|&)+"></td></tr>
<tr><td>;	  Phone Number :;</td><td><input type="tel" size="25" id="phoneid" placeholder="XXX XXX XXXX" pattern="\d{3} \d{3} \d{4}"></td></tr>
</form>

<form name=order>
//javascript to get an customer information
<br>

<br>

<center><input type=button value="Price your Order" id="clickMe" onClick="clicked();"></center>

</form>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

我修复了您的代码,但是这个问题还有很多。这实际上不是存储数据的正确方法。您应该将信息从表单发布到服务中。

SELECT *
FROM data d
WHERE 
    type = 'one' 
    AND name = 'a' 
    AND status = 'verified'
    AND NOT EXISTS (
        SELECT 1 
        FROM data d1
        WHERE d1.client_id = d.client_id AND d1.type = 'one' and d1.name = 'b'
    )