如何将strike标记替换为输入类型文本?

时间:2013-12-18 06:33:17

标签: javascript jquery

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

HTML文字

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">.

3 个答案:

答案 0 :(得分:0)

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

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

});

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

答案 1 :(得分:0)

只需添加以下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;
 });

答案 2 :(得分:0)

试试这个:

HTML

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

的Javascript

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