html的非标准属性,HTML标签上的非标准属性。好东西吗坏事?你的意见?

Another option would be to define something like this in Javascript:

var link_titles = {link1: "Title 1", link2: "Title 2"};

Then you can use this later in your Javascript code, assuming your link has an ID that corresponds to the ID in this hashtable.

It doesn't have the disadvantages of the other two methods: no non-standard attributes nor the ugly hidden span.

The disadvantage is that it might a bit of an overkill for things as simple as your example. But for more complex scenarios, where you have more data to pass, it's a good choice. Especially considering that the data is being passed as JSON, so you can pass complex objects with ease.

Also, you keep data separate from the formatting, which is a good thing for maintainability.

You can even have something like this (which you can't really do with the other methods):

var poi_types = {1: "City", 2: "Restaurant"};

var poi = {1: {lat: X, lng: Y, name: "Beijing", type: 1}, 2: {lat: A, lng: B, name: "Hatsune", type: 2}};

...

Hatsune

And since you most probably use some server-side programming language, this hash table should be trivial to generate dynamically (just serialize it to JSON and spit it in the header section of the page).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值