我是 js 和 jquery 的新手。 html
<div id="answerdiv" name="answerdiv" class="answerdiv">
<div id="answerweightdiv" class="answerweightdiv">
<input id="answerweight" class="answerweight" type="number" name="answerweight" placeholder="Weight" maxlength="3" tabindex="7" onBlur="exchangeLabelsanswerweight(this);">
</div>
</div>
上面的字段是动态创建的 n 次 1 在另一个下面我正在尝试创建一个仅将当前活动元素转换为标签而不是其他元素的 js 函数
js
function exchangeLabelsanswerweight(element)
{
var result = $(element).val();
if(result!="")
{
$(element).remove();
$("#answerweightdiv").append("<label id='answertext' onClick='exchangeFieldanswerweight(this);'>"+result+"</label>");
}
}
function exchangeFieldanswerweight(element)
{
var result = element.innerHTML;
$(element).remove();
$("#answerweightdiv").append("<input id='answerweight' class='answerweight' value="+result+" type='number' name='answerweight' placeholder='Weight' maxlength='3' tabindex='7' onBlur='exchangeLabelsanswerweight(this);'>");
}