带有Hashtags的Popstate?(Popstate with Hashtags?)
我有一个使用AJAX动态将内容加载到div中的站点。
执行此操作的链接是具有href =“#”的锚点和用于触发AJAX的onclick事件。
当我点击回来时,这让我没有历史记录,所以如果我加载一个页面,然后另一个页面然后单击返回,它什么都不做。
代码的基本版本是这样的:
<script type="text/javascript"> function loadXMLDoc(url) { <!-- Load XML Script here. --> } </script> </head> <body> <div id="myDiv"> <!-- Target div. --> </div> <a href="#1" onclick="loadXMLDoc('1.txt')">Click Me.</a> <a href="#2" onclick="loadXMLDoc('2.txt')">Click Me.</a> <a href="#3" onclick="loadXMLDoc('3.txt')">Click Me.</a> </body>
我想知道的是,我可以给每个链接一个不同的“#”然后使用一个popstate处理程序来调用相应的事件,所以如果我点击链接1,2和3然后开始点击后退按钮,它我会回到2然后再等1 ..
我打算使用history.js并在loadXML脚本中开始使用pushstate,但我认为整个操作历史记录有点脏和不可靠。
我在思考正确的方向还是有更好的方法?
目前我的所有链接都使用“#”,以便在加载更多内容时弹回页面顶部,但我希望能够尽可能返回。
任何帮助都会很棒。
I have a site that uses AJAX to dynamically load content into a div.
The links to do so are anchors with href="#" and an onclick event to trigger the AJAX.
This leaves me without a history when I click back, so if I load one page, then another and click back, it does nothing.
A basic version of the code is this:
<script type="text/javascript"> function loadXMLDoc(url) { <!-- Load XML Script here. --> } </script> </head> <body> <div id="myDiv"> <!-- Target div. --> </div> <a href="#1" onclick="loadXMLDoc('1.txt')">Click Me.</a> <a href="#2" onclick="loadXMLDoc('2.txt')">Click Me.</a> <a href="#3" onclick="loadXMLDoc('3.txt')">Click Me.</a> </body>
What I would like to know is, can I give each link a different "#" and then use a popstate handler to call the appropriate event, so if I click link 1, 2 and then 3 and then start hitting the back button, it'll go back to 2 and then 1 etc..
I was going to use history.js and start using pushstate in the loadXML script but I think the whole manipulating history thing is a bit dirty and unreliable.
Am I thinking on the right lines or is there a better way?
Currently all my links just use "#" so that it pops back to the top of the page when loading more content but I'd like to be able to go back if possible.
Any help would be great.
原文:https://stackoverflow.com/questions/16146034
最满意答案
你不应该使用内部框架类,而是依赖公共API ...
var textbox = grid.SelectedRow.Cells[1].Controls[0] as TextBox;
you are not supposed to use internal framework classes, rather rely on the public api...
var textbox = grid.SelectedRow.Cells[1].Controls[0] as TextBox;
相关问答
更多-
从C到C#的#define转换(#define conversion from C to C#)[2021-10-31]
没有。 考虑以下: LERP(x++,1,2); c代码也可能会有两次增加x的副作用[它是未定义的@ phresnel],而c#代码是完美定义的,并且只会增加x一次。 结果也可能不同,因为[宏]中的第a和第二个可能具有不同的值,因为它可能在第一个中增加。 no. consider the following: LERP(x++,1,2); The c code might also have a side effect of increasing x twice [it is undefined as me ... -
C#内部属性“可读”在quickwatch中但不使用反射?(C# - Internal Properties “readable” in quickwatch but not using reflection?)[2023-12-13]
使用这些标志 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance 此操作不需要GetProperty标志。 您可能也想添加Static 。 注意:您可以将标志与|结合使用 ,因为它们的整数值是2的幂。 看到这个答案 。 注意 (为了回应拉尔曼和小腿对安全问题的反思) 总有一种方法可以编写不好或危险的代码。 这取决于你是否做到。 反思不是常规的做事方式,而是面向特殊工具的编程,如o / r-mappers或分析工具。 反思 ... -
if ((latch_state & 0x1) != 0) 应该管用。 通常,不评估为布尔值的C ++条件与0进行隐式比较,“true”表示表达式不为0。 if ((latch_state & 0x1) != 0) should work. Normally, C++ conditions which don't evaluate to a boolean are doing an implicit comparison to 0, with 'true' being that the expressi ...
-
C#中的视频转换(video conversion in C#)[2023-04-12]
如果你使用ffmpeg很好,你可能想看看这个问题的答案。 If you are fine with using ffmpeg, you may want to look at answers to this question. -
您尝试的C#等价物中的各种代码似乎与原始C ++代码不对应。 这是一个直接可编译的翻译,假设您在某处定义了“isVowel”: using System.Collections.Generic; public enum TKeyIdentity { _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _1, _2, _3 } public class TraverseKeyPaths { public readonly ...
-
尝试这个 Dim m As MenuItem = TryCast(sender, MenuItem) audioDevice = (IIf(m.Index>0, filters.AudioInputDevices(m.Index-1), Nothing)) IIf功能MSDN文档 由于不推荐使用IIf函数,请使用这样的方法 If m.Index>0 Then audioDevice = filters.AudioInputDevices(m.Index-1) Else audioDev ...
-
在C中,只需将指针传递给第k个项(即array+k ),就可以“制作”一个没有前k个元素的array+k ,因为C中的数组通过传递第一个元素的位置来传递(这种“新”数组根本不是新的,因为它将引用“原始”数组的相同元素)。 在C#中,这不起作用,因为数组不是作为指向连续内存的指针处理的; 如果你想快速修复,你可以创建一个新数组,使用Array.Copy将元素从第k个复制到最后,然后将这个新数组传递给递归函数,但这很慢,如果没有用,算法修改数组的元素(修改不会反映在其他数组中,因为它们现在是副本)。 一个更好的 ...
-
在转换此代码时,最好的方法是什么? 这取决于您的目标和应用。 如果您计划跨产品/版本共享代码,那么您最好拥有一个API来抽象平台详细信息并为每个平台分离代码。 我应该专注于转换使用MonoTouch库吗? iOS(或MonoTouch)不支持WPF API。 因此,您最接近的方法是查看MonoTouch提供的iOS API(即在查看第三方库之前查看已有的内容)。 您可以通过使用iOS CoreGraphics (通常与旧的System.Drawing模型非常相似)找到类似的功能。 对于位图图像,您应该阅读C ...
-
你不应该使用内部框架类,而是依赖公共API ... var textbox = grid.SelectedRow.Cells[1].Controls[0] as TextBox; you are not supposed to use internal framework classes, rather rely on the public api... var textbox = grid.SelectedRow.Cells[1].Controls[0] as TextBox;
-
Marshal.PtrToStringAnsi()是将IntPtr转换为字符串所需的。 IntPtr持有char* , Marshal.PtrToStringAnsi()是你的家伙。 但是,你已经尝试过但没有成功。 所以我怀疑你的问题更为根本。 也许你在互操作边界的两边处理大结构的方式上存在二进制不匹配。 这是互操作的一部分,其中不同的工具表现不同。 应始终使用out参数返回结构。 将本机代码更改为: __declspec(dllexport) int compute_calc(int opt, const ...