2011-02-04 96 views
0

我可以动态删除文本框吗?动态删除文本框

+1

这将有助于解释你正在尝试做什么以及到目前为止尝试过的内容。如果您在某人已经回答问题后没有用另一个问题完全替换某个问题,这也会很有帮助。 – 2011-02-04 18:01:43

+1

@ B蜥蜴:我想自动删除文本框。如果我将一个光标移到评论上时采用了stackoverflow,我会得到一个十字图标。我该怎么做? – gaurav 2011-02-04 18:15:30

回答

1

在OP看到评论后编辑):

要获得StackOverflow上一样的功能,你可以做这样的事情:

HTML:

<div class="comment"> 
This is a test this is a test this is a test. 
</div> 

的JavaScript :

$(".comment").hover(function() { 
    $(this).append("<span class='close'>X</span>"); 
}, function() { 
    $(this).find("span.close").remove(); 
}).delegate(".close", "click", function() { 
    $(this).closest("div.comment").remove(); 
}); 

这里有一个工作示例:http://jsfiddle.net/andrewwhitaker/xQTSb/

这一切都显得有些忙乱,但这里发生了什么:

  • 用途hover,这需要一个函数,在mouseenter,并再次执行上mouseleave
  • 在这些函数中,删除注释的span分别被添加或删除。
  • delegate用于将点击事件绑定到跨度(因为直到用户将鼠标悬停在comment div之外,span才存在)。
+0

当我将光标移动到文本框的边缘时,我需要一个小十字图标,如果我点击它应该删除 – gaurav 2011-02-04 18:01:14

0
$('#your_text_box_id').remove()