javascript - 如何从 jQuery 移动脚本中删除基本标记?

标签 javascript jquery html

在 jQuery Mobile 中:

  • 如何删除 <base href="">页面中的标签
  • 如何禁用基本 href?

相关代码:

 // Test for dynamic-updating base tag support ( allows us to avoid href,src attr rewriting )
 function baseTagTest() {
     var fauxBase = location.protocol + "//" + location.host + location.pathname + "ui-dir/",
         base = $("head base"),
         fauxEle = null,
         href = "",
         link, rebase;

     if (!base.length) {
         base = fauxEle = $("<base>", { "href": fauxBase }).appendTo("head");
     } else {
         href = base.attr("href");
     }

     link = $("<a href='testurl' />").prependTo(fakeBody);
     rebase = link[0].href;
     base[0].href = href || location.pathname;

     if (fauxEle) {
         fauxEle.remove();
     }
     return rebase.indexOf(fauxBase) === 0;
 }

最佳答案

base 元素是 jQuery Mobile 导航模型的关键组成部分,以至于当 jQuery Mobile 站点加载到无法动态更新 base 元素的浏览器中时,它会在 url 前面加上 base。

满足您需求的两个建议:

  1. 使用绝对文件路径而不是相对路径

  2. 使用 jQuery Mobile Download Builder并自定义 jQuery Mobile 应用程序所需的模块。我最初的猜测是您希望排除导航模块以移除基本元素功能。

关于javascript - 如何从 jQuery 移动脚本中删除基本标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15096031/

相关文章:

javascript - 使用 Jquery 从多维 JSON 数组获取变量

javascript - 如何在子组件中提交时呈现数据

javascript - EnumDropDownListFor 更改 ajax 调用操作并将所选值分配给数据库的一个字段

html - ASP.NET MVC 多种布局

html - 在 CSS 中使图像适合 flexbox 容器

javascript - HTML <body onload =""> 不会停止

javascript - 在javascript html中访问列表中的元素

javascript - 如何通过子 &lt;input&gt; 的 OnClick 删除动态父 <tr>

javascript - Ajax 填充的选择元素在返回 json 的 ajax 数据库插入调用上相互冲突

javascript - AJAX 调用 ASP MVC 操作