我试图在 onclick 函数中放置一个动态参数值。问题是它似乎将其转换为小写,并在其前面添加了一个额外的空间。任何帮助将不胜感激,谢谢。
这是我的代码的codepen.io:http://codepen.io/theller5567/pen/GZwBrE?editors=1010
这是我的功能:
createList: function(scope){
var country = scope;
var cc = country.countryCode;
var ccc = cc.toUpperCase();
console.log(ccc);
if(ccc){
var listItem = '<li><a href="#" onclick="setCountry("'+ccc+'","'+country.country+'");getDistribution(event);">'+country.country+'</a></li>';
return listItem;
}
},
以下是 dom 中的 listitem 之一的示例:
<a href="#" onclick="setCountry(" il","israel");getdistribution(event);">Israel</a>
控制台日志将显示全部大写的所有国家/地区代码,但 dom 中的代码显示为小写,并且前面有一个额外的空格。