哈希和数字
Hash and the Numbers
我在jQuery Elastislide中有一个库。
图库中的每张图片都有相应的哈希。
例如:*www.example.com/gallery.html#4/title_of_the_picture*
因此,当我重新加载第四个图像时,页面会加载第四张图像。
但是,当我在哈希中标题之前没有数字的情况下重新加载时,图片不会加载。
*www.example.com/gallery.html#title_of_the_picture*
我可以删除这个号码吗?如果可以的话,Jquery中要使用的正确代码是什么?
jQuery代码:
Gallery = (function() {
// index of the current item
var imageIndex = 0;
if (window.location.hash) {
var imageIndexStr = window.location.hash.replace('#', ''); // remove #
imageIndex = parseInt(imageIndexStr, 0); // convert to int
}
var current = imageIndex;
// mode : carousel || fullview
mode = 'carousel',
// control if one image is being loaded
anim = false, init = function() {
// (not necessary) preloading the images here...
$items.add('<img src="ajax-loader.gif"/><img src="black.png"/>').imagesLoaded(function() {
// add options
_addViewModes();
// add large image wrapper
_addImageWrapper();
// show first image
_showImage($items.eq(current));
});
}
}
代码行:
var imageIndexStr = window.location.hash.replace('#', '');
imageIndex = parseInt(imageIndexStr, 0); // convert to int
我们将尝试将哈希的第一个字符转换为int,但如果第一个字符不是有效的int(就像你所说的那样,如果你删除了4,就会出现这种情况),那么JavaScript将在这一点上出错,不再继续。
此外,根据文档,-0似乎不是parseInt()
的有效选项。
编辑:替换了W3Schools 的链接
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/parseInt
相关文章:
- 根据选项卡内部的文本链接中的哈希ID动态选择jqueryUI选项卡
- Steam Web API:I'我不知道该如何处理这个看起来像哈希的url来生成图像
- AngularJS:获取链接中没有哈希的查询字符串值
- 如何在Google chrome安全首选项文件中创建扩展安全哈希代码
- 如何在浏览器重新加载时保存位置哈希状态
- jQuery scrollTop-哈希错误
- 动态添加哈希标记;t工作
- 在Javascript中实现对哈希值的暴力攻击
- 如何在JavaScript/Node中计算SHA256哈希和Base64字符串编码
- 使用Javascript/jQuery以编程方式将当前锚点/哈希/片段附加到任何表单操作url
- 可以在React Native中制作一个自哈希应用程序
- 重定向不带哈希的URL-Ember.JS
- 正在测试主干事件哈希
- JavaScript对象作为哈希?复杂性是否大于O(1)
- 如何在JavaScript中实现哈希表
- 如何根据传入的哈希标签发送PHP请求
- 哈希和数字
- 如何从哈希中获取数字
- 将长文本转换为数字(如哈希,md5),这将在PHP和JS中得到相同的结果
- Ajaxpageloak与哈希(#)与例外,当有数字(Ex.: # 1)