我有2个div,第一个有显示内容的标签,但是当你点击编辑按钮时,它应该显示div =edit和第1个标签的内容链接到它的输入(相同的id)。
I have 2 divs, the first one has the label with the content to show, but when you click the "edit" button, it should show you the div="edit" and the content of the 1st label inside of the input that is linked to it (same id).
另一方面,我看到当你在输入内输入内容的网站时,预览的原始标签div正在实时更新。
By the other way, I saw sites that when you type something inside that input, the original label of the "preview" div is getting updated in realtime.
有人可以帮助我使用脚本吗?谢谢!
Could someone help me with the script? Thank you!
<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>推荐答案
您可以使用以下内容。请注意,虽然我将字段的ID更改为不同。在同一页面上为同一个id提供多个控件并不是一个好习惯。有些浏览器无法使用它,反正它真的没有意义。
You can use something like below. Notice though that I changed the id of the fields to be different. It is not a good practice to give multiple controls on the same page the same id. Some browsers do not work with this and it really doesn't make sense anyways.
$(document).ready( function() { $("#companyNameText").keypress( function() { $("#companyNameLabel").html(this.value); }); $("#companyCountryText").keypress( function() { $("#companyCountryLabel").html(this.value); }); });更多推荐
Javascript:使用jquery编辑预览
发布评论