Javascript:DOM问题

时间:2016-04-29 15:55:43

标签: javascript dom dhtml

function a1() {
var newParagraph = document.createElement('div');
newParagraph.className = '"alert alert-success" role="alert"';
newParagraph.appendChild(document.createTextNode("<b>Richtig!  </b>Du scheinst dich um dein Wissen zu bemühen."));
document.getElementById('content').appendChild(newParagraph);
window.setTimeout(partB,3000);
addText();
}

嘿那里!我正在尝试创建一个互动测验。而不是将“警报”作为答案,我想在网站上添加一个元素,我选择了它:

<div class="alert alert-success" role="alert"><b>Richtig!  </b>Du scheinst dich um dein Wissen zu bemühen.</div>

此。

我想在一个名为'alarm'的父div标签之后添加它作为一个孩子。 这不起作用?

1 个答案:

答案 0 :(得分:2)

function a1() {
  var newParagraph = document.createElement('div');
  newParagraph.className = 'alert alert-success';
  newParagraph.setAttribute('role', 'alert');
  newParagraph.innerHTML = '<b>Richtig!  </b>Du scheinst dich um dein Wissen zu bemühen.';
  document.getElementById('content').appendChild(newParagraph);
  window.setTimeout(partB, 3000);
  addText();
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<div class="alert alert-success" role="alert"><b>Richtig! </b>Du scheinst dich um dein Wissen zu bemühen.</div>

<a href='javascript: a1();' class='btn btn-primary'>Add</a>
<div id='content'></div>