简体   繁体   English

无法将 append 下拉列表的选定文本转换为表格单元格值

[英]unable to append dropdown's selected text to a table cell value

i have a table with a header row and a drop down with three options.我有一个表,其中包含 header 行和一个包含三个选项的下拉列表。 I want to append the selected option's text/value of drop down to the header row value of table.我想 append 将所选选项的文本/下拉值下拉到表的 header 行值。 Please help on how can i accomplish this task.请帮助我如何完成这项任务。

Example: if first option of drop down is "First", and table header row value has "This is header", I want to append this "First" to "This is header" and show it as "This is header first"示例:如果下拉菜单的第一个选项是“First”,并且表 header 行值具有“This is header”,我想将 append 这个“First”改为“This is header”并将其显示为“This is Z099FB995346F31C75EZEF6”

[DEMO][1]


  [1]: https://jsfiddle.net/nocw3478/

Good attempt.很好的尝试。 As others have noted, you need an on-change listener.正如其他人所指出的,您需要一个 on-change 监听器。 Here's one I put together for you, it's not perfect, but it will help you get started.这是我为您整理的一个,它并不完美,但它会帮助您入门。 Replace all your JavaScript in your example with this:将示例中的所有 JavaScript 替换为:

var original_header_text = document.querySelector('#headerText').innerText;
document.querySelector('#myOptions').addEventListener('change', function(event) {
  var selected = {
    'text': event.target[event.target.selectedIndex].text
  };
  document.querySelector('#headerText').innerText = original_header_text + selected.text;
});

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

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