如何为JavaScript语句传递值?

时间:2015-01-21 19:58:53

标签: javascript

我想将值传递给Javascript语句。可能吗? 例如:

function Show(msg, Id, Msgtype) { // I need to pass this Id argument to below javascript innerHtml statement
  var strVar = "";
  strVar = "Hello" + Msgtype + " <i class='icon-remove close'></i> " + msg + "</div>";
  document.getElementById("???").innerHTML = strVar; // ??? should be the Id above in the function arguments
}

或者换句话说,我该如何实现这种情况?

1 个答案:

答案 0 :(得分:4)

只需通过Id,就像这样

document.getElementById(Id).innerHTML = strVar;