我意識到我幾乎複製一個excel表格;在一個插件,預期的行爲是: 被點擊一個含有值時,它內被替換的是得到是相同的值,因此可以進行編輯。它的工作原理,但問題是當點擊新創建的文本輸入時,該值被重置或擦除爲''。什麼一直在刪除點擊文本輸入值?
我不知道那是什麼,我試過了事件監聽器,我試過.unbind焦點,點擊,點擊,焦點,因爲它似乎重新點擊文本框會觸發刪除它的東西。我用F12事件偵聽器和步入一切,但我認爲這可能是對自己的東西jQuery也默認,但我想知道,如果anyonw知道是什麼原因造成這種現象。
$("td").click(function(event)
{
var value = $(this).text(); // gets the text inside section inside the td
var column = $(this).get(0).id; //gets id="" of the td that is how I indentify columns
var parent = $(this).parent().get(0).id; //gets the id of the row <tr id="x"><td id=">
if(column == "a" || column == "b")
{
return;
}
else if (column == "d" || column == "c")
{
$(this).children().replaceWith('<input type=email value=' + value + '>');
$(this).children().focus();
}
else
{
$(this).children().replaceWith('<input type=text value="' + value + '">');
$(this).children().focus();
}
$(this).children().focusout(function(event){
var new_value = $(this).val();
$(this).parent().addClass("edited");
$(this).replaceWith('<section>' + new_value + '</section>');
});
類似的問題已經被問here,但它並沒有解決我的問題,也沒有解決我的問題。他們建議他.append新的html,而不是注入它。因此,也許有使用的問題「.replaceWith()?」 ...... IDK的,我搜索無處不在。
你能提供他的HTML去與JavaScript代碼http://jsfiddle.net/qzbrzm4x/(打開你的控制檯和運行)?或者在jsfiddle.net中加入一個例子 – Silkster 2014-09-23 16:49:51
http://jsfiddle.net/qzbrzm4x/1/在那裏你可以看到行爲,在選擇光標區域時,它也停在空格處,我注意到了,對此也有任何想法? – Dracovic5 2014-09-23 23:20:02