简体   繁体   English

动态将输入内容添加到div

[英]Dynamically adding contents of an input to a div

I have an input field and a div. 我有一个输入字段和一个div。 I want to put a live preview in a div. 我想在div中进行实时预览。 This is the code I have so far: http://jsfiddle.net/6Wp2j/1/ 这是我到目前为止的代码: http : //jsfiddle.net/6Wp2j/1/

$('#source').on('keyup', function() {

});

I know that I need to look out for a keyup but I don't know how to move the contents to the div. 我知道我需要注意键入内容,但是我不知道如何将内容移动到div。 Can anyone tell me how to do this please? 谁能告诉我该怎么做?

Here's a fiddle 这是一个小提琴

You just need to add $(".preview").html(this.value); 您只需要添加$(".preview").html(this.value); inside your code. 在您的代码中。

Something like should work: 类似的东西应该起作用:

$("#source").on("keyup", function(){
    $("#mydiv").html($(this).html());
});

This should do the trick 这应该可以解决问题

$('#source').on('keyup', function() {
  var data = $(this).val();
  $('#result').html(data);
});
$('#source').on('keyup', function() {
    $(".preview").html(this.value);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM