简体   繁体   English

如何将javascript创建的节点输入数组

[英]how do I input javascript created nodes into an array

I'm trying to push elements generated from this 我正在尝试推送由此产生的元素

function myFunction() 
{ 

    var x=document.getElementById("stat"); 
    var para=document.createElement("p"); 
    var node=document.createTextNode(stat.value); 
    para.appendChild(node);
    var element=document.getElementById("output"); 
    element.appendChild(para); 
    stat.value="" 

} 

into an array to run through 4 separate functions to determine their avg., med., mode, and standard deviation. 分为四个独立的函数,以确定它们的平均,中间,模式和标准偏差。 I thought I'd be about to target them with an getElementByTagName, but it doesnt seem to work. 我以为我要使用getElementByTagName来定位它们,但似乎不起作用。

It's a typo. 这是一个错字。

You're using stat as a variable name instead of x . 您使用stat作为变量名称,而不是x

The most important thing for a variable it's the name... you should pick variable names more carefully. 变量最重要的是名称...您应该更仔细地选择变量名称。

Functions have both a name and a semantic and the semantic (logic) is of course more important than the name (not saying that the name is not important, of course). 函数既具有名称又具有语义,并且语义(逻辑)当然比名称更重要(当然,并不是说名称并不重要)。

But variables are basically just names. 但是变量基本上只是名称。

Something like this? 像这样吗

function myFunction(element) 
{ 
  var stat=document.getElementById(element); 
  var para=document.createElement("p"); 
  var node=document.createTextNode(stat.value); 
  para.appendChild(node);
  var element=document.getElementById("output"); 
  element.appendChild(para); 
  stat.value="" 
} 

var elements = ['stat', 'stat2', 'stat3', 'stat4']

for (var i = 0; i < elements.length; ++i) {
  myFunction(elements[i])
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用javascript中的鼠标悬停事件删除我在javascript中创建的DOM节点? - How do I remove DOM nodes that I created in javascript using mouseover events in javascript? 如何从JavaScript中的数组访问DOM节点? - How do I access DOM nodes from an array in javascript? 如何定位通过JavaScript创建的孩子的孩子的节点? - How do I target the nodes of a child of a child that I created through JavaScript? 如何代理通过 JavaScript function 创建的嵌套数组? - How do I proxy a nested array created through a JavaScript function? JavaScript:如何将用户输入与数组进行比较? - JavaScript: How do I compare user input to an array? 如何在 javascript 中搜索用户输入数组? - How do I search for an array of user input in javascript? 如何在Javascript中为动态创建的输入字段添加唯一ID? - How do I add unique IDs to dynamically created input fields in Javascript? 我如何在 html canvas 和 javascript 上显示矩阵数组(我使用 1 和 0 创建的)? - How do i display a matrix array(that i created using 1s and 0s) on the html canvas with javascript? 如何搜索使用 javascript 创建的表 - How do I search a table that is created with javascript 如何从用户输入的 javascript 中创建一个新的对象数组 - How do I do a new array of objects from user input in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM