如何根据URL显示特定的模式?
我正在使用作为一个响应的框架引导。
我有两种模式(实际上有很多):
使用url和jquery打开模型:
$(document).ready(function() {
if(window.location.href.indexOf('#privilege_10') != -1) {
$('#privilege_10').modal('show');
}
});
$(document).ready(function() {
if(window.location.href.indexOf('#privilege_11') != -1) {
$('#privilege_11').modal('show');
}
});如果URL为index.php#privilege_10,则将打开特权_10的模式,如果URL为index.php#privilege_11,则将打开特权_11的模式。
由于有许多这样的调制解调器,为每个调制解调器添加代码将非常长。
那么,在编写一次代码时,我如何才能做到呢?(比如循环)
如果是的话,可以将if(window.location.href.indexOf('#privilege_10') != -1)更改为检查url是否包含#特权
应该像我们在php ( $('what ever the url contains [#privilege_10 or #privilege_11]').modal('show'); )中所做的那样,将$('#privilege_10').modal('show');改为$('#privilege_10').modal('show'); ($_GET[''])。
发布于 2019-05-01 13:07:55
不要检查特定的模式,而是让URL的散列值作为模式的ID。所以,您所需要做的就是获取散列值,然后使用该值调用模式。
$(window.location.hash).modal('show');如果这种模式不存在,什么都不会发生。如果是的话,模态就会显示出来。注意,此示例没有对window.location.hash进行任何检查。
发布于 2019-05-01 13:26:51
您可以尝试从URL中获得锚点,然后可以验证它是否正确,如果是的话,弹出模式。
我要做的是:
$(function () {
var anchor = window.location.hash;
if (anchor.split('_')[0] == '#privilege') {
$(anchor).modal('show');
}
}https://stackoverflow.com/questions/55936547
复制相似问题