我如何禁用和启用文本框使用jquery

How can I disable and enable the textbox using with jquery?

本文关键字:jquery 文本 启用 何禁用      更新时间:2023-09-26

这里有一个文本框

<input name="" type="text" id="txt" onblur="txt(this)"/>
jquery

function txt(th) {
  $(th).hide().after('<span class='"dfk'">' + $(th).val() + '</span>');  
}

我已经禁用了文本框,并显示了文本框的值,但再次单击文本框的值。文本框应该启用值为。

你可以这样做(如果我明白你需要什么):

<input name="" type="text" id="txt" />
$('#txt').blur(function(){
    $(this).hide().after('<span class="dfk">' + $(this).val() + '</span>');  
});
    $('.dfk').live('click', function(){
       $(this).prev().show();
       $(this).remove();
    });

here提琴:http://jsfiddle.net/qJ3sY/2/

Edit - i更正为使用span

DEMO HERE

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#txt")
    .focus(function() {
      $(this).removeClass("txtOff").addClass("txtOn");
    })
    .blur(function() {
      $(this).removeClass("txtOn").addClass("txtOff");
    });
});
</script>    
<style>
.txtOn { border:1px solid black; background-color:light-grey}
.txtOff { border:1px solid white; background-color:white}
</style>
<input name="txt" type="text" id="txt" class="txtOff" value="" placeholder="Click to edit" />