我认为这是一个简单的例子,但是除了在此处输入文本帖子.
I thought this one was a simple one but I wasn't able to find anything out there, except one post here on STO.
问题是代码不起作用.我创建了一个小提琴,以便您自己查看.
Problem is the code doesn't work. I created a fiddle so you can see it for yourself.
这是小提琴中的代码:
$('#someTextBox').keyup(function() { $('#target').html(this.val()); });但是,我的HTML与示例有所不同:
However, my HTML is a bit different than the example:
<textarea name="comment-box" id="comment-box" class="required"></textarea> ... <p id="comment-preview"></p>我需要帮助的是一种显示"comment-preview"容器上textarea上键入内容的方式.
All I need help with is a way to display what's being typed on the textarea on the "comment-preview" container.
在此方面为我提供指导的任何帮助都将倍受赞赏.
Any help guiding me on this one is greatly appreciated.
推荐答案将this.val()更改为$(this).val()
演示:: jsfiddle/FjNzS/1/
.val是jQuery函数,可以从jQuery对象访问.在处理程序内部,this是DOM对象,因此您需要用$()包装它以使其成为jQuery对象.
.val is a jQuery function and can be accessed from jQuery object. Inside the handler, this is DOM object and so you need to wrap it with $() to make it a jQuery object.
更多推荐
在输入时显示文字
发布评论