У меня есть следующий код:Изменение типа элемента с помощью JQuery
$('#theForm').on('click', 'button', function(e){
var attrs = { };
var str =e.target.id;
var newStr = str.substring(0, str.length-1);
$("#file01b").replaceWith(function() {
attrs.text = $(this).text();
return $("<a />", attrs);
});
var field= document.getElementById(newStr);
field.value= field.defaultValue;
document.getElementById(newStr).style.display = "none";
});
Весь код:http://jsfiddle.net/K9eWL/3/
и когда я нажимаю на первой кнопке «Remove File» она отлично работает, так что я пытался сделать это автоматически, чтобы он работает для всех кнопок:
$('#theForm').on('click', 'button', function(e){
var attrs = { };
var str =e.target.id;
var newStr = str.substring(0, str.length-1);
$("#str").replaceWith(function() {
attrs.text = $(this).text();
return $("<a />", attrs);
});
var field= document.getElementById(newStr);
field.value= field.defaultValue;
document.getElementById(newStr).style.display = "none";
});
все треску e:http://jsfiddle.net/K9eWL/3/
но он не работает, где ошибка?
Спасибо за помощь.
'не work' не является заменой для краткого объяснения того, что вы ожидаете, что ваш код, чтобы сделать – charlietfl
Если вы используете JQuery, с помощью JQuery. 'document.getElementById (newStr) .style.display =" none ";' должен быть '$ ('#' + newStr) .hide()'. – j08691