简体   繁体   English

访问“此”表单元格的值

[英]Accessing 'this' table cells value

I have a form, after form has been filled and add button pressed - all the values from the form get to PouchDB and then into the table in the browser. 填写表单并按下添加按钮后,我有了一个表单-表单中的所有值都到达PouchDB,然后进入浏览器中的表。 I need to make an "edit" option. 我需要做一个“编辑”选项。 The idea is: 这个想法是:

<td ondblclick='updateVaucher()' style='cursor: pointer'>"+data[i].doc.vaucherID+
                "</td>

Now the question is: how do I get the value of the cell (which is an ID) so that then I could download the rest of the information into the form? 现在的问题是:如何获取单元格的值(即ID),以便可以将其余信息下载到表单中?

I would like it to be something like that: 我希望它是这样的:

function updateVaucher(){
  var mydoc = this.td.value;
  ...
}

To get a reference to the element inside the function, you can pass the element to it from the event handler: 要获得对函数内部元素的引用,可以从事件处理程序中将元素传递给它:

ondblclick='updateVaucher(this)'

You can get the content of an element via innerText or textContent (cross-browser): 您可以通过innerTexttextContent (跨浏览器)获取元素的内容:

function updateVaucher(ele){
  var mydoc = ele.textContent || ele.innerText;
  ...
}

Learn more about event handling in the browser . 在浏览器中了解有关事件处理的更多信息

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM