简体   繁体   English

使用$('div')和CSS(JavaScript)时如何在textarea中显示输出

[英]How to show the output in textarea when using $('div') and CSS (JavaScript)

When I use this codes, it Prints the result in a new html page, how can I print the results in a nominated textarea? 当我使用此代码时,它将结果打印在新的html页面中,如何在指定的textarea中打印结果? lets I want the result to be shown in: bookForm.myText.value 让我希望结果显示在:bookForm.myText.value

Update: PLEASE NOTE ONLY THE bTitle IS SUPPOSED TO BE ITALIC 更新:请仅注意bTitle应该是斜体

HTML: HTML:

<div contenteditable="true"></div>

CSS: CSS:

span{
    font-style: italic;
}

JavaScript: JavaScript:

bTitle = bookForm.txtTitle.value;
bName = bookForm.txtName.value;
bNumber = bookForm.txtNumber.value;

var concatBook = "<span>"+bTitle+"</span> by "+bName+" sold "+bNumber+" Copies."
$('div').html(concatBook);

Add Textarea in with id "mytext" 在ID为“ mytext”的地方添加Textarea

     <textarea id="mytext" name="somename"></textarea>

Add Javascript 添加JavaScript

      bTitle = bookForm.txtTitle.value;
      bName = bookForm.txtName.value;
      bNumber = bookForm.txtNumber.value;

      var concatBook = ""+bTitle+" by "+bName+" sold "+bNumber+" Copies.";
      $('#mytext').val(concatBook);  //this will display result in textarea
      $('#mytext').css('font-style', 'italic');

Step 1 第1步
Create a textarea with id, here id is "myTextarea" 创建一个具有ID的textarea,此处的id为“ myTextarea”

<textarea id="myTextarea" name="somename"></textarea>


Step 2 第2步
Javascript Java脚本

bTitle = bookForm.txtTitle.value;
    bName = bookForm.txtName.value;
    bNumber = bookForm.txtNumber.value;

    var concatBook = ""+bTitle+" by "+bName+" sold "+bNumber+" Copies.";
    $('#myTextarea').val(concatBook);  //this will display result in textarea

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

相关问题 如何仅使用 javascript 或 css 将 textarea 背景设置为透明以在放置在其后面/上方的 div 上显示其内容 - how to set textarea background transparent to show its contents on div placed behind/above it using either javascript or css only 如何使用CSS或Javascript隐藏和显示DIV - How To Hide and Show DIV using CSS or Javascript 修改文本区域后,如何在div中获取输出? - How to get the output in a div when a textarea is modified? JavaScript JSON 输出到一个<textarea>或 &lt;div&gt; - JavaScript JSON output into a <textarea> or a <div> 仅当文本从 div 溢出时,如何在 reactjs 中使用纯 css javascript 显示更多内容 - How to display show more only when text overflows from a div using pure css javascript in reactjs 如何仅使用javascript和css隐藏和显示表单内的div - how to hide and show a div that is inside of a form using only javascript and css 识别文本区域中的URL并使用javascript将其显示为输出 - Identify URLs in a textarea and show them as output using javascript jquery javascript 如何在 textarea 后最近的 div 中显示一些 html - jquery javascript how to show some html in the closest div after a textarea 使用javascript css隐藏show div - hide show div using javascript css CSS / Javascript-使用悬停显示下拉div - CSS/Javascript - using hover to show dropdown div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM