这可能是一个愚蠢的错误,但我似乎无法让它发挥作用。我正在尝试使用 id=variable id 的 div 更改所有 H2 元素的 innerhtml。
var numberOfQuestions = $('.question').length;
var id = "question"+(numberOfQuestions);
clone.id=id;
document.documentElement.getElementById(id).getElementsByTagName( "h2" ).innerhtml= "Question"+(numberOfQuestions);
我想我在这里做错了:document.documentElement.getElementById(id).getElementsByTagName( "h2" ).innerhtml= "Question"+(numberOfQuestions);
nrtire 脚本:
<script type="text/javascript">
function copyAppendRow() {
var question = document.getElementById("question");
var clone=question.cloneNode(true);
var numberOfQuestions = $('.question').length;
var id = "question"+(numberOfQuestions);
clone.id=id;
var questiondiv = document.getElementById(id);
var h2s = questiondiv.getElementsByTagName("h2");
for(var h = 0; h < h2s.length; h++ ) {
h2s[h].innerHTML = "Question"+(numberOfQuestions); }
if($('#questionsuccess').css('display') == 'none'){
$('#questionsuccess').fadeIn('fast');
$('#questionsuccess').fadeOut(4000);
}
}
</script>