Jquery 如何使用直接链接到模式窗口
我想使用以下代码:Jquery 如何使用直接链接到模式窗口,jquery,bootstrap-modal,Jquery,Bootstrap Modal,我想使用以下代码: function popModal() { // code to pop up modal dialog } var hash = window.location.hash; if (hash.substring(1) == 'modal1') { popModal(); } 我将如何在以下模态示例中使用它: <a href="#" data-target=".bs-nps-modal" data-toggle="modal"> 新JS: v
function popModal() {
// code to pop up modal dialog
}
var hash = window.location.hash;
if (hash.substring(1) == 'modal1') {
popModal();
}
我将如何在以下模态示例中使用它:
<a href="#" data-target=".bs-nps-modal" data-toggle="modal">
新JS:
var id=getUrlParameter('id');
如果(id='modal1'){
popModal();
}
函数popmodel()
{
$('#modal1').modal('show');
}
函数getUrlParameter(sParam)
{
var sPageURL=window.location.search.substring(1);
//模拟urlhttp://example.com?id=modal1
//在实现此代码时删除
var sPageURL='id=modal1';
var sURLVariables=sPageURL.split('&');
对于(变量i=0;i
我对接受的解决方案有一些问题,需要对其进行调试
我认为这是一个简化的实现
function popModal()
{
$('#modaltopop').modal('show');
}
function getUrlParameter(sParam)
{
return window.location.search.substring(1);
}
var id= getUrlParameter('link_parameter');
if (id == 'link_parameter') {
popModal();
}
<a href='/?link_parameter'>click me</a>
函数popmodel()
{
$('modaltopop').modal('show');
}
函数getUrlParameter(sParam)
{
返回window.location.search.substring(1);
}
var id=getUrlParameter('link_参数');
if(id=='link_参数'){
popModal();
}
只要链接参数与“getUrlParameter('link_参数')中的参数匹配
samplurl.com/?link_parameter您是否询问如何使用锚链接或外部URL打开模式?或者anchor link.example.com/modal?id=modal1-我希望看到这样的东西,当你进入页面时,弹出窗口已经打开,直接打开页面。那么,这个例子的外部URL是什么我希望看到这样的东西,可以直接用弹出窗口打开页面。外部URL:example.com/#modal1get URL参数:我一定是做错了什么。这是我的代码:在这种情况下,ID是否正确?
var id= getUrlParameter('id');
if (id == 'modal1') {
popModal();
}
function popModal()
{
$('#modal1').modal('show');
}
function getUrlParameter(sParam)
{
var sPageURL = window.location.search.substring(1);
//simulate url http://example.com?id=modal1
//remove when implementing this code
var sPageURL='id=modal1';
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];
}
}
}
function popModal()
{
$('#modaltopop').modal('show');
}
function getUrlParameter(sParam)
{
return window.location.search.substring(1);
}
var id= getUrlParameter('link_parameter');
if (id == 'link_parameter') {
popModal();
}
<a href='/?link_parameter'>click me</a>