我想在 alert 中打印 dict a ,(有可能吗?)或在第三个文本区域(三个)中打印id=p
. 我读过这个问题,我用过
document.getElementById("p").value=JSON.stringify(a);;
alert("myObject is " + a.toSource());
console.log(a);
这些不起作用。例子是:
<!DOCTYPE HTML>
<html>
<head>
<title>Example - print the dict</title>
</head>
<body>
<input id = 'button1' type = 'button' value = 'print the dict' onclick="updateHistory()"/>
<script type = 'text/javascript'>
var count ="?foo=1&oo=298529982";
function updateHistory()
{
var a = new Array();
for (var i = 0; i < document.formparam.elements.length; i++)
{
var field = document.formparam.elements[i];
a[field.name] = field.value;
}
document.getElementById("p").value=JSON.stringify(a);;
alert("myObject is " + a.toSource());
console.log(a);
}
</script>
<form method="GET" name="formparam" id="formparam" ><table><tr><td><textarea name="name" >john</textarea></td><td><textarea name="surname">jackold</textarea></td></tr></table></form>
<textarea id="p"></textarea>
</body>
</html>