Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何访问输入框javascript的行号_Javascript - Fatal编程技术网

如何访问输入框javascript的行号

如何访问输入框javascript的行号,javascript,Javascript,我正在寻找关于如何让这个工作的建议 <input type='text' id='%(settling_cell_id)s' data-row='%(row)s' value='%(val)s' size = '9' style='height:20px' onchange='getvalue(this)'> getvalue = function(settling_amount_cell){ console.log(settling_

我正在寻找关于如何让这个工作的建议

<input type='text' id='%(settling_cell_id)s' data-row='%(row)s' value='%(val)s' size = '9' style='height:20px' onchange='getvalue(this)'>

getvalue = function(settling_amount_cell){                   
    console.log(settling_amount_cell.value);
    console.log(settling_amount_cell.id);
    console.log(settling_amount_cell.data-row);
}
我可以访问this.value、this.size和this.id,但this.data-row或this['data-row']未定义


如何访问数据行?

它是一个属性,特别是一个data-*属性。在现代浏览器中使用它有两种方式:

使用:

使用:


请注意,数据集较新,因此在过时的浏览器上不可用。还请注意,dataset对数据应该是什么样子进行了一些猜测,并对其进行了解析。例如,如果属性中只有数字,则返回的值类型将是数字而不是字符串。相反,getAttribute始终会给您一个完全不变的字符串。

您应该看看这个-动态生成的元素必须正确添加到文档中,才能让JavaScript看到:
settling_amount_cell.getAttribute("data-row");
settling_amount_cell.dataset.row; // or dataset["row"], but not dataset["data-row"]