gpt4 book ai didi

javascript - Rows-Element,这些空格是从哪里来的?

转载 作者:行者123 更新时间:2023-11-27 23:44:19 27 4
gpt4 key购买 nike

首先:我的问题是,通过 DOM 从一行中将字符串插入到表单的多个字段中,值的开头和结尾都有很多空格。

我想做的:在我双击的行中查找单元格的值,并将这些值放入表单的字段中。

HTML 相当于:

<form>
<fieldset>
<legend> Very Important </legend>
<label for="input_representing_all_the_inputs">
<input id="input_representing_all_the_inputs"></input>
</fieldset>
</form>

<table id="issue_table" class="sortable", border="1" >
<tr ondblclick="values_into_form(issue_table)">
<td>
a value
</td>
<td>
another one
<td>
</tr>
<tr ondblclick="values_into_form(issue_table)">
<td>
here's also another value
</td>
<td>
aaand one more.
</td>
</tr>
</table>

<table id="not_the_issue_table" class="sortable", border="1">
[...] blabla looks similar [...]
</table>

现在我得到了一个 js 函数来从表中查找值并将它们放入表单中。

function values_into_form( id ) {
//find index of row with given id
for (i = 0; i<= document.getElementById("accl_content").rows.lenght; i++){
if ( document.getElementById("issue_table").rows[i].id == id) {
var idx = i;
break;
}
}

// now insert the values into the editor-form
document.getElementById("input_representing_all_the_inputs" =
document.getElementById("issue_table").rows[idx].cells[0];
// repeat the above for each input_field with the specific cell_idx.
}
}

那么现在,让我们看一下 issue_table 的第一个中的第一个。该值是“一个值”。但是,输入字段将包含类似“值”的内容。

我在制作这个时是否犯了一个特定的错误?我不想要一个消除空格的解决方案,我想要一个真正的解决方案,我想说,我根本不希望它们出现。

我刚接触 JS,来自 lua。因此,如果我犯了一些概念上的错误,如果你能在旁注中告诉我,我会很高兴。

最佳答案

将您的 html 更改为:

<table id="issue_table" class="sortable", border="1" >
<tr ondblclick="values_into_form(issue_table)">
<td>a value</td>
<td>another one<td>
</tr>
<tr ondblclick="values_into_form(issue_table)">
<td>here's also another value</td>
<td>aaand one more.</td>
</tr>
</table>

空格是因为在你的 html 中有空格。您当然也可以使用 javascript 去除开始和结束的空格。但如果您不想这样做,上述解决方案应该可行。

关于javascript - Rows-Element,这些空格是从哪里来的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30574746/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com