getElementById('pcode') 许多元素都已编号
我有一个文档,当单击链接时,该表的每一行中都会显示一个结果表,其中有一个带有 SPAN 标记的 TD 元素,其中有一个 id,从 2 开始,最多可以递增到 400(即id=“pcode2”)。
我需要获取其内部 HTML 值并将它们写入 Javascript 函数?、数组?细绳?后跟一个逗号,用于地图的另一个 Javascript 函数。
数据经过预先排序,通过单击链接调用地图来获取路线。 span id 永远不会超过 400。
最终目的地需要如下所示。
var via = ("pcode2," "pcode3,", "pcode4");
其中 pcode 等于 SPAN 的内部 HTML 值(邮政编码)。
谢谢
贾斯汀
I have a a document that when an link is clicked a table of results is displayed within each row of this table there is a TD element with a SPAN tag, inside of this is an id which starts at 2 and can increment up to 400 (i.e. id="pcode2").
I have a need to get the inner HTML values of this and write them into a Javascript function?, array? string? followed by a comma to use on another Javascript function for a map.
The data is pre sorted and the map is called by clicking a link to get the route. the span id's will never reach more than 400.
the end destination needs to look like this..
var via = ("pcode2," "pcode3,", "pcode4");
Where pcode is equal to the innerHTML value of the SPAN which is a postcode.
Thanks
Justin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的意思是这样的:
?
如果没有,你应该澄清我们的问题。
但不确定为什么需要逗号。如果您想稍后连接这些值,只需使用
join()
:示例:
更新: 来自 文档,我认为你必须这样做(假设
map
全局可用):请注意
locations
只是一个数组。在原始代码中,您创建了一个嵌套数组。而且您似乎不需要尾随逗号,只需要一系列位置。You mean something like:
?
If not, you should clarify our question.
Not sure why you need the comma though. If you want to concatenate the values later, you can just use
join()
:Example:
Update: From the documentation, I think you have to do this (assuming
map
is globally available):Note that
locations
is just a single array. In your original code, you create a nested array. And you don't seem to need a trailing comma, just an array of locations.