当我使用此代码时,它将结果打印在新的html页面中,如何在指定的textarea中打印结果?让我希望结果显示在:bookForm.myText.value
更新:请仅注意bTitle应该是斜体
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);
最佳答案
在ID为“ mytext”的地方添加Textarea
<textarea id="mytext" name="somename"></textarea>
添加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');