<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<button onclick="myFunction()">点我</button>
<p id="demo"></p>
<script>
var temp = {a:"gaga"}
function myFunction() {
document.getElementById("demo").innerHTML = "temp.a "+temp.a+" temp.b "+temp.b+" temp.c "+temp.c;
}
</script>
</body>
</html>
添加属性直接 OBJECT.XXX=XXXX 即可
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<button onclick="myFunction()">点我</button>
<p id="demo"></p>
<script>
var temp = {a:"gaga"}
temp.b = "44"
temp.c = "22"
function myFunction() {
document.getElementById("demo").innerHTML = "temp.a "+temp.a+" temp.b "+temp.b+" temp.c "+temp.c;
}
</script>
</body>
</html>