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

For simplicity, I'm not going to show too much code, but the variables are set, and the following

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744788589a4593776.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信