目前我有一个点击功能,可以在点击时显示一些项目详细信息。
https://localhost:5001/MyPage?ID=3
$(".show-detail").click(function (){
var item-id = $(this).data('item-id');
$("#red-section").hide();
$(".red-panel").hide();
$("#blue-" + item-id).show();
});
问题是,如果我刷新页面,它会再次隐藏该部分。我可以让 JS 在页面加载时查找处理程序,如果存在,则运行上述函数来隐藏某些部分并显示感兴趣的部分?
https://localhost:5001/MyPage?ID=3&ItemID=4
如果 ItemID 存在,则显示 #blue-4。
最佳答案
Js方法。另外@Ryan Wilson
在评论中给了你一个关于 Razor 的想法
(function(){
let currentUrl = window.location.href;
let itemId = currentUrl.split('ItemID=')[1]
if(!!itemId){
var item-id = $(this).data(itemId);
$("#red-section").hide();
$(".red-panel").hide();
$("#blue-" + item-id).show();
}
})();
关于javascript - 如果找到 Razor 处理程序,则调用 JS 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58140318/