简体   繁体   English

html链接不起作用href javascript参数过长

[英]html link does not work href javascript parameter is too long

<a href="javascript:change('page_details_1','time,restime\n1387519869249,1196\n1387519906965,1368\n........')><img src="expand.jpg" alt="expand/collapse" id="page_details_1_image"></a>

in href i am calling a javascript function "change". 在href中,我正在将javascript函数称为“更改”。 The second parameter "\\n1387519869249,1196\\n1387519906965,1368\\n...." is a very long value about 5070 characters.but at 5052 characters the link works. 第二个参数“ \\ n1387519869249,1196 \\ n1387519906965,1368 \\ n ....”是一个非常长的值,大约为5070个字符。但是在5052个字符处,链接有效。

Is there a limit to number of characters that can pass through href? 可以通过href传递的字符数是否有限制? the data is used to generate trend graph . 该数据用于生成趋势图。 If there is such a limitation what would be the best way to pass such info to javascript function? 如果有这样的限制,什么是将此类信息传递给javascript函数的最佳方法?

Try 尝试

<a href="javascript:void(0);" onclick="change('page_details_1','time,restime\n......'); return false;"><img src="expand.jpg" alt="expand/collapse" id="page_details_1_image"></a>

This way your URL isn't overly long. 这样,您的网址就不会太长。

The maximum limit of an href link is 2000: https://stackoverflow.com/a/417184/2413722 . href链接的最大限制为2000: https : //stackoverflow.com/a/417184/2413722

If it's just data that you are wanting to send, then add a data attribute and get JavaScript to read that value (this is simplified somewhat in jQuery). 如果只是您要发送的数据,请添加一个data属性并获取JavaScript来读取该值(在jQuery中对此进行了简化)。

Here's a great article on passing data with JSON. 这是一篇有关通过JSON传递数据的好文章。 I'm using PHP and it's much easier than I thought :) http://betterexplained.com/articles/using-json-to-exchange-data/ 我正在使用PHP,它比我想象的要容易得多:) http://betterexplained.com/articles/using-json-to-exchange-data/

Why not save the long term into a variable 为什么不将长期保存到变量中

value = "yes";
<a href="javascript:alert(value)">blubb</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM