将html输入类型标记更改为动态创建的标签

时间:2013-09-24 08:21:48

标签: javascript jquery html dynamic

我是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);'>");
}

0 个答案:

没有答案