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

时间:2015-06-20 05:03:17

标签: javascript html css textarea

当我使用此代码时,它会在新的html页面中打印结果,如何在指定的textarea中打印结果?让我希望结果显示在:bookForm.myText.value

更新:请仅注意bTitle是否为ITALIC

HTML:

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

CSS:

span{
    font-style: italic;
}

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);

2 个答案:

答案 0 :(得分:3)

使用id“mytext”

添加Textarea
ch

添加Javascript

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

答案 1 :(得分:0)

第1步 创建一个带id的textarea,这里的id是“myTextarea”


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


第2步 使用Javascript


    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