我是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次,低于另一个 我正在尝试创建一个仅将当前活动元素转换为标签而不是其他元素的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);'>");
}