文本与input框的来回切换
html代码:
<label>电话:</label><label id="phone">875252</label>
<button type="button" class="btn " id="btn">重置</button>
<button type="button" class="btn " id="confirm">确定</button>
js代码:
<script>
$(function () {
$("#btn").click(function () {
var phone = $("#phone");
var txt2 = phone.text();
var input2 = $("<input type='text' value='"+txt2+"'/>");
phone.html(input2);//从文本变为文本框
$("#confirm").click(function () {
var v2 = $(input2).val();
// alert(v2);
$("#phone").html(v2);//从文本框变为文本
})
})
})