我意识到我几乎复制一个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