Javascript 使用纯js向div添加注释
如何仅使用js(或js/jquery)向某个div元素添加注释 例如: 我有一张表格:Javascript 使用纯js向div添加注释,javascript,jquery,html,css,Javascript,Jquery,Html,Css,如何仅使用js(或js/jquery)向某个div元素添加注释 例如: 我有一张表格: <form action="#" id="create" method="post"> <fieldset> <legend><strong>Add your comment</strong></legend> <p> <label for="author">Name &
<form action="#" id="create" method="post">
<fieldset>
<legend><strong>Add your comment</strong></legend>
<p>
<label for="author">Name <abbr title="Required">*</abbr></label>
<input name="author" id="author" value=""
required="required" aria-required="true"
pattern="^([- wdu00c0-u024f]+)$"
title="Your name"
type="text" spellcheck="false" size="20" />
</p>
<p>
<label for="email">Email <abbr title="Required">*</abbr></label>
<input name="email" id="email" value=""
required="required" aria-required="true"
pattern="^(([-wd]+)(.[-wd]+)*@([-wd]+)(.[-wd]+)*(.([a-zA-Z]{2,5}|[d]{1,3})){1,2})$"
title="Your email address"
type="text" spellcheck="false" size="30" />
</p>
<p>
<label for="text">Comment <abbr title="Required">*</abbr></label>
<textarea name="text" id="text"
required="required" aria-required="true"
title="Your comment"
spellcheck="true" cols="40" rows="10"></textarea>
</p>
</fieldset>
<fieldset>
<button name="preview" type="submit">Preview</button>
<button name="save" type="submit">Submit Comment</button>
</fieldset>
</form>
<div id="comments"></div>
添加您的评论
名字*
电子邮件*
评论*
预览
提交评论
之后,我将尝试提交此表单,并在提交后向表单旁边的div元素添加textarea内容。显然,如果不重新加载页面,我就做不到
您能帮我解决这个问题吗?使用纯JS:
document.getElementById('comments').innerHTML = 'Form sent!';
使用jQuery:
$('#comments').html('Form sent!');
使用纯JS:
document.getElementById('comments').innerHTML = 'Form sent!';
使用jQuery:
$('#comments').html('Form sent!');
将以下javascript函数添加到页面代码中
<script>
function updateComment()
{
document.getElementById("comments").innerHTML = document.getElementById("text").value;
}
</script>
函数updateComment()
{
document.getElementById(“注释”).innerHTML=document.getElementById(“文本”).value;
}
并在“提交评论”按钮的“Onclick”事件中调用此函数
提交评论
在页面代码中添加以下javascript函数
<script>
function updateComment()
{
document.getElementById("comments").innerHTML = document.getElementById("text").value;
}
</script>
函数updateComment()
{
document.getElementById(“注释”).innerHTML=document.getElementById(“文本”).value;
}
并在“提交评论”按钮的“Onclick”事件中调用此函数
提交评论
您可以使用纯角度来获得最佳性能。您可以使用纯角度来获得最佳性能。