2017-01-24 43 views
-3

我试图使文本存储在变量sendSpecialChat大写,但我找不出为什么它不起作用。这其实不是我想要做的,但我简化了代码:使变量文本大写

var sendSpecialChat = hi; 
 

 
document.writeIn(sendSpecialChat.toUpperCase()); 
 

 
document.getElementById('print').innerHTML = "sendSpecialChat";
<p id="print"></p>

虽然,这是行不通的。我的代码有什么问题?

+0

'的ReferenceError:喜不defined','类型错误: document.writeIn不是一个函数,而sendSpecialChat和sendSpecialChat是不同的东西 – Oriol

回答

2

sendSpecialChat.toUpperCase()会给你一个字符串的大写版本。你有你的代码的一些问题,你需要使用引号(“)周围的字符串,而不是变量名称的

var sendSpecialChat = "hi"; 
 

 
document.getElementById('print').innerHTML = sendSpecialChat.toUpperCase();
<p id="print"></p>

+0

有没有办法把'toUpperCase'放在'document.getElementById ...'中 –

+0

Like store var sendSpecialChatUpper = sendSpecialChat.toUpperCase();'then'... innerHTML = sendSpecialChatUpper;'' – dtkaias