我使用while循环编写了下面的代码,如下所示
<p>
<input id="txtBox<?php echo $a; ?>" type="text" value="1" style="display:none;" />
<span id="txtBoxValue<?php echo $a; ?>">1</span>
</p>
当我单击或选择跨度时,我需要将其转换为文本字段,取消选择后它将再次返回跨度文本
对于这个任务,我写了多个 jquery 函数,但我需要它是一个函数,这可能吗?
先感谢您
<script>
$(function() {
$('#txtBoxValue1').on('click', function() {
$(this).hide();
$('#txtBox1').show();
});
$('#txtBox1').on('blur', function() {
var that = $(this);
$('#txtBoxValue1').text(that.val()).show();
that.hide();
});
$('#txtBoxValue2').on('click', function() {
$(this).hide();
$('#txtBox2').show();
});
$('#txtBox2').on('blur', function() {
var that = $(this);
$('#txtBoxValue2').text(that.val()).show();
that.hide();
});
});
</script>