gpt4 book ai didi

javascript - 错误: 'History.Adapter' is null or not an object

转载 作者:行者123 更新时间:2023-11-28 08:43:59 26 4
gpt4 key购买 nike

js 并且在除 IE8 之外的所有浏览器中都可以正常工作。我有下一个错误

Error: 'History.Adapter' is null or not an object

我的代码:

@Scripts.Render("~/bundles/history")
<script type="text/javascript">

var History = window.History;
$(document).ready(function () {
change(1, '#catalog');

History.Adapter.bind(window, 'statechange', function () {
try {
var State = History.getState();
$('#Products').load(State.url);
} catch (e) {

}
});

function change(id, ItemMenu) {
var url = $('#' + id).val();
try
{
History.pushState({}, null, url);
}
catch(e)
{
}

}
</script>

和脚本:

   bundles.Add(new ScriptBundle("~/bundles/history").Include(
"~/Scripts/History/history.adapter.jquery.js",
"~/Scripts/History/history.html4.js",
"~/Scripts/History/history.js",
"~/Scripts/History/json2.js"

));

最佳答案

为了在 IE 8 中正确工作,您需要将初始化 History.js 和 History.Adapter.bind 放入 $(document).ready(...)这适用于所有浏览器...以及 IE 8

@Scripts.Render("~/bundles/history")
<script type="text/javascript">
$(document).ready(function () {
var History = window.History;

History.Adapter.bind(window, 'statechange', function () {
try {
var State = History.getState();
$('#Products').load(State.url);
} catch (e) {

}
});
});


function change(id, ItemMenu) {
var url = $('#' + id).val();
try
{
History.pushState({}, null, url);
}
catch(e)
{
}

}
</script>

关于javascript - 错误: 'History.Adapter' is null or not an object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20115100/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com