Как заменить элемент забастовки на текст типа ввода? В это время я понятия не имею, если какое-либо решение, пожалуйста, скажите мне здесь!
Текст 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">.
Просто добавьте следующий оператор 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;
});
Если я хорошо понимаю ваш вопрос, вы хотите этого?
$('strike').each(function(){
$(this).replaceWith("<input type=\"text\" value=\"" + $(this).text() + "\" />");
});
jsfiddle: http://jsfiddle.net/M88u4/
each
? Я имею в виду, если вы уже используете другие функции jQuery для замены тега Strike, почему бы не использовать each
? Можете ли вы объяснить, почему вы хотите использовать цикл for ()?
Попробуй это:
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);
});
});
<strike>
<input>
тегами<input>
с помощью JavaScript?