【问题标题】:Set Dynamic Id using JS using Counter使用 JS 使用 Counter 设置动态 ID
【发布时间】:2017-12-13 14:34:48
【问题描述】:

我正在尝试使用 cnt 计数器变量动态设置单元格 ID。但是,在浏览器中查看页面源时,我得到的不是数字,而是 cnt 字。

怎么了

 q1TargetVolume.setAttribute('id', `q1TargetVolume-${cnt}`);  

【问题讨论】:

  • dataRowCell4 = dataRow.insertCell(2); q1TargetVolume = document.createElement("input"); q1TargetVolume.setAttribute('type', 'text'); q1TargetVolume.setAttribute('maxlength', '8'); q1TargetVolume.setAttribute('size', '4'); q1TargetVolume.setAttribute('id', q1TargetVolume-${cnt}); q1TargetVolume.setAttribute('value', record.get('q1_target_volume__c')); dataRowCell4.appendChild(q1TargetVolume);
  • 在我的代码中,这里删除了刻度

标签: javascript html sfdc


【解决方案1】:

我猜你希望将计数值附加到字符串q1TargetVolume-,并将其用作元素的 id。你可以试试这个方法。

q1TargetVolume.setAttribute( 'id', 'q1TargetVolume-' + cnt );//cnt is the count value you wish to append

【讨论】:

  • 我试过了,但是如果我在浏览器中查看页面源代码,我只会看到 cnt 变量名,而不是变量中的值。很郁闷
  • 实际上,它正在工作。我使用 Chrome 中的开发人员工具检查了这些值。谢谢
  • 不知道该怎么做。寻找链接。好的,刚刚得到它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-22
  • 2018-12-15
  • 1970-01-01
  • 1970-01-01
  • 2017-05-04
  • 2017-12-29
  • 2013-11-02
相关资源
最近更新 更多