window.location.hash差异写入url和标签
window.location.hash difference write url and a tag
html代码
<div class="fakeSearch">
<input id="searchInput" type="text" placeholder="Search">
<img id="searchImg" class="clickAble" src="./img/search.png">
</div>
脚本
window.addEventListener("hashchange", ChangePage);
$('#searchImg').on('click', function(){
var word = decodeURIComponent($('#searchInput').val());
window.location.hash = '#search:'+word;
});
var ChangePage = function(){
var myUrl = window.location.hash;
var argStr = myUrl.split("''");
argStr = argStr[0].split(":");
argStr[0] = argStr[0].replace("#", "");
$('#mainPlace > div').css('display','none');
if(myUrl === ""){}
...
else if(argStr[0]==='search'){
$('#searchPage').css('display','block');
InitLoadSearch(decodeURIComponent(argStr[1]));
}
}
var InitLoadSearch = function(){
/* call ajax data and print masonry */
}
编写直接键入url时工作#search:123
但是,window.location.hash='#search:'+word代码不起作用
更正确的是,默认页面是砖石页面
*砖石-我用http://masonry.desandro.com/
搜索页面也是砖石页面
默认页面的网格是间断的。(位置重置),在搜索时单击并返回按钮
仅限破解android移动chrome
每个网格都是其他定义的
此外,
<a href="#search:code"></a>
这是正常的工作!仅
window.location.hash = "#search:"+variable;
就是休息。
总之,我知道写url、标签href和window.location.hash
不幸的是,您很难理解。
我试过你的密码:https://jsfiddle.net/3ouLyxds/它似乎起了作用。我只是更改了代码的顺序,否则根本不起作用:
var ChangePage = function(){
var myUrl = window.location.hash;
var argStr = myUrl.split("''");
argStr = argStr[0].split(":");
argStr[0] = argStr[0].replace("#", "");
$('#mainPlace > div').css('display','none');
if(argStr[0]==='search'){
$('#searchPage').css('display','block');
InitLoadSearch(decodeURIComponent(argStr[1]));
}
}
var InitLoadSearch = function(str){
alert(str);
}
window.addEventListener("hashchange", ChangePage);
$('#searchImg').on('click', function(){
var word = decodeURIComponent($('#searchInput').val());
window.location.hash = '#search:'+word;
});
相关文章:
- Shoutcast流url在html5音频标签中不起作用
- 由于存在标签('#')特殊字符,URL无法工作
- Facebook标签页更改url时不带window.location
- 使用 Javascript/Jquery 预填充表单字段和来自 URL 的标签
- SEO机器人是否总是遵循A标签的href属性中的URL,即使点击/点击被Javascript拦截
- 我如何找到包含在给定url的元标签中的页面描述(如果它有描述)
- 带有标签的动态url的社交共享
- 火狐插件不会打开带有url的新标签
- IMACRO的脚本会打开2个带有特定URL的新标签
- 我应该在正文标签上使用 onload 还是检测 URL
- 如何阻止任何滑块向 URL 添加哈希标签
- 将标签追加到 URL 的状态提供程序
- 带有锚点标签、http:// 或URL的PHP注释以及其余的HTML标签是纯文本
- 如果锚具有标签/url/mail/phone,则发出警报
- 参考“;href"而不是html中锚点标签中的url
- 将JSON检索到的图像URL放置在<李>标签
- 从字符串中移除BBCode URL标签
- 我如何在脚本标签下使用url标签
- 在javascript的url标签中的图像位置
- 将外部JSON URL标签和值拉到新的Array中