我有一個按鈕,當我點擊它時,我將它的兄弟變換爲包含它曾經保存的文本的輸入。將文本更改爲輸入,然後再取消選擇
這工作正常。
但是,取消選擇輸入後,我需要再次回到文本,但問題是,const變量正在被覆蓋?
不管怎麼說,這是我目前的HTML和JS:
$(function() {
$(document).on("click", "table.table-striped > tbody > tr > td > a.copy-btn", function(e) {
e.preventDefault();
const $this = $(this),
text = $this.parent().parent().find("td.link").text();
$this.parent().parent().find("td.link").html(`<input type="text" class="form-control" value="${text}">`);
$this.parent().parent().find("td.link input").select();
if ($this.parent().parent().find("td.link input").blur()) {
$this.parent().parent().find("td.link").html(text);
}
});
return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-striped">
<thead>
<tr>
<th class="title">link name</th>
<th class="title">Platform</th>
<th class="title">Link</th>
</tr>
</thead>
<tbody>
<tr>
<th class="body-text" scope="row">1</th>
<td class="body-text">Mark</td>
<td class="body-text link">Otto</td>
<td class="body-text"><a href="#" class="copy-btn">Copy</a>
</td>
<td class="body-text"><a href="#" class="more-btn">More</a>
</td>
</tr>
<tr>
<th class="body-text" scope="row">1</th>
<td class="body-text">Otto</td>
<td class="body-text link">Mark</td>
<td class="body-text"><a href="#" class="copy-btn">Copy</a>
</td>
<td class="body-text"><a href="#" class="more-btn">More</a>
</td>
</tr>
</tbody>
</table>
你有幾個語法錯誤?例如'.find(「td.link」.html(text)'等 – adeneo
不知道他們爲什麼會在那裏,在我複製粘貼到你的代碼中,那裏werent那裏,也許這是SO編輯器的整潔功能再次看代碼,會重新輸入代碼 – SkullDev
雖然你知道如何實現我的目標是什麼想法嗎?嘗試檢測模糊,聚焦等,但沒有做到這一點正如我所說的那樣。 – SkullDev