为什么这两种类型的变量不同?怎么解决呢?

时间:2019-06-13 21:33:36

标签: javascript variables

请帮忙..... 如果我将以下变量(1)设置为函数locationData(locationURL,locationCategory,locationImg,locationTitle,locationAddress,locationPhone,locationStarRating,locationRevievsCounter):

var locations=[[locationData('listing-single2.html', '....', 'images/all/8.jpg', '......', "1327 Intervale Ave, Bronx, NY ", "+38099231212", "5", "27"), 40.72956781, -73.99726866, 0, markerIcon],[locationData('listing-single.html', '.....', 'images/all/1.jpg', '....', "W 85th St, New York, NY ", "+38099231212", "4", "5"), 40.76221766, -73.96511769, 1, markerIcon]];

然后代码运行良好! 但是如果我有一个div

 <div class='trick' id='123'>
    [locationData('listing-single2.html', '....', 'images/all/8.jpg', '......', "1327 Intervale Ave, Bronx, NY ", "+38099231212", "5", "27"), 40.72956781, -73.99726866, 0, markerIcon],[locationData('listing-single.html', '.....', 'images/all/1.jpg', '....', "W 85th St, New York, NY ", "+38099231212", "4", "5"), 40.76221766, -73.96511769, 1, markerIcon]
 </div>

并尝试用以下内容替换上面的var位置,结果不好。...

var location= document.getElementById("123").innerHTML;
var locations= "["+location+"];";

毫不逊色地用

检查结果
document.getElementById("1234").innerHTML = locations;

我对id为“ 1234”的div的结果相同:

[[locationData('listing-single2.html', '....', 'images/all/8.jpg', '......', "1327 Intervale Ave, Bronx, NY ", "+38099231212", "5", "27"), 40.72956781, -73.99726866, 0, markerIcon],[locationData('listing-single.html', '.....', 'images/all/1.jpg', '....', "W 85th St, New York, NY ", "+38099231212", "4", "5"), 40.76221766, -73.96511769, 1, markerIcon]];

0 个答案:

没有答案