2013-02-23 65 views
0

我是jQuery的新手。预览未加载按键

我创建了一些东西,如当我点击add按钮时显示textarea,并在textarea中输入要显示预览的数据。

但预览无法工作

http://jsfiddle.net/nGfh4/

HTML:

<div id='TextBoxesGroup'> 
    <div id="TextBoxDiv1"> 
     <label>Textbox #1 :</label> 
     <input type='textbox' id='textbox1'> 
    </div> 
</div> 
<div id="add_comment_box"></div> 
<input type='button' value='Add Button' id='addButton'> 
<input type='button' value='Cancel Button' id='canButton'> 

的JavaScript:

$(document).ready(function() { 

    var commentNode = $('#lp-comment'); 
    //$(' #live-preview-form textarea').bind('blur keyup',function() 
    commentNode.keypress(function (event) { 
     alert('test');; 
     commentNode.text($('#comment').val()); 
     commentNode.html($('#lp-comment').html().replace(/\n/g, '<br />')); 
    }); 

    $("#addButton").click(function() { 

     // $('#add_comment_box').css('display','block'); 
     var newTextBoxDiv = $(document.createElement('div')).attr("id", 'form').hide(); 
     // newTextBoxDiv.after().html('<label>Textbox # : </label> <input type="text" name="textbox" id="textbox" value="" >'); 
     newTextBoxDiv.after().html(
      '<div id="live-preview-form" class="lp-block">' + 
      '<textarea name="comment" id="comment" class="input" rows="10"></textarea>' + 
      '</div>' + 
      '<div id="live-preview-display" class="lp-block">' + 
      '<div id="lp-comment">' + 
      '</div>'); 
     newTextBoxDiv.appendTo("#add_comment_box").slideDown(); 
     // $("#TextBoxesGroup").append(newTextBoxDiv); 
    }); 

    $("#canButton").click(function() { 

     $('#form').slideUp(function() { 
      $('#form').remove(); 
     }); 
     return false; 
    }); 
}); 
+0

http://jsfiddle.net/nGfh4/看到这个链接 – 2013-02-23 10:28:27

+1

欢迎来到StackOverflow!你能对你的问题更具体一点吗?你越具体,我们就越容易帮助你! – 2013-02-23 10:30:22

+0

@crynix jsfiddle.net/nGfh4看到这个链接 – 2013-02-23 10:31:55

回答

0

见本page演示在底部。

在“Type Something”之外的文本框中输入内容时,会触发keyup函数。它也触发了一个按钮单击事件。

在处理程序键入函数中,您可以编写显示预览的逻辑。