最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I set .innerHTML equal to two variables - Stack Overflow

programmeradmin0浏览0评论

For simplicity, I'm not going to show too much code, but the variables are set, and the following code is within a conditional. I'm just trying to show the var _offsetX and var _offsetY at the same time.

window.document.getElementById('cssposition').innerHTML = _offsetX _offsetY;

For simplicity, I'm not going to show too much code, but the variables are set, and the following code is within a conditional. I'm just trying to show the var _offsetX and var _offsetY at the same time.

window.document.getElementById('cssposition').innerHTML = _offsetX _offsetY;
Share Improve this question asked Sep 10, 2012 at 20:57 William SmithWilliam Smith 8521 gold badge13 silver badges23 bronze badges 2
  • Any reason you can't just use console.log(_offsetX, _offsetY)? Looks like you're just debugging to me. – zzzzBov Commented Sep 10, 2012 at 21:00
  • window.document.getElementById('cssposition').innerHTML = _offsetX +''+_offsetY; – Shahrokhian Commented Sep 10, 2012 at 21:04
Add a ment  | 

4 Answers 4

Reset to default 3

try:

window.document.getElementById('cssposition').innerHTML = _offsetX +" " + _offsetY;

Just use the + operator:

window.document.getElementById('cssposition').innerHTML = "X=" + _offsetX + " Y=" +  _offsetY;

concat these two variables? ...innerHTML = "" + _offsetX + _offsetY;

Concatenate two variables and then try out, but make a note this a redundant way,

window.document.getElementById('cssposition').innerHTML=_offsetX.concat(_offsetY);

Note: This ignores the space

发布评论

评论列表(0)

  1. 暂无评论