如何将删除标记替换为输入类型文本

How to replace strike tag to input type text?

本文关键字:输入 类型 文本 替换 删除      更新时间:2023-09-26

如何将删除元素替换为输入类型文本?我现在不知道是否有任何类型的解决方案请在这里告诉我!

文本

In the <b>joy</b> of <strike>other</strike>, lies our <strike>own</strike>.

替换文本 :

In the <b>joy</b> of <input type="text">, lies our <input type="text">.

如果我很好地理解你的问题,你想要这个吗?

$('strike').each(function(){
    $(this).replaceWith("<input type='"text'" value='"" + $(this).text() + "'" />");
});

JSFIDDLE: http://jsfiddle.net/M88u4/

只需添加以下 jQuery 语句

 // search all strike element and replace it 
 $('strike').replaceWith(function(){
        //create input element
        var input = $('<input>',{
            type: 'text',
            value: $(this).html()
        });
        //replace with input element
        return input;
 });

试试这个:

.HTML

<div id="test">
    In the <b>joy</b> of <strike>other</strike>, lies our <strike>own</strike>.
</div>

爪哇语

$(function(){
    var strikes = $('#test').children('strike');
    var inputText = "<input type='text' />";
    strikes.each(function(){
        $(this).replaceWith(inputText);
    });
});