我有2个div,第一个有显示内容的标签,但是当你点击“编辑”按钮时,它应该显示div =“edit”和第1个标签的内容链接到它的输入(相同的id)。
另一方面,我看到网站在您输入内容时,“预览”div的原始标签会实时更新。
有人可以帮我写剧本吗?谢谢!
<html>
<body>
<div id="preview">
<label id="companyName" class="workExperience">
This is my company
</label>
<label id="companyCountry" class="workExperience">
This is my company Country
</label>
<input type="button" value="edit"/>
</div>
<div id="edit">
<label>Company Name: </label>
<input type="text" id="companyName" />
<label>Company Country: </label>
<input type="text" id="companyCountry" />
</div>
</body>
</html>
答案 0 :(得分:2)
您可以使用以下内容。请注意,虽然我将字段的ID更改为不同。在同一页面上为同一个id提供多个控件并不是一个好习惯。有些浏览器无法使用它,反正它真的没有意义。
$(document).ready(
function()
{
$("#companyNameText").keypress(
function()
{
$("#companyNameLabel").html(this.value);
});
$("#companyCountryText").keypress(
function()
{
$("#companyCountryLabel").html(this.value);
});
});