0

是否可以将我的网址中的“#”替换为“/”(domain.com#home 到 domain.com/home)?如果是这样,你会怎么做?

$(document).ready(function () {
   $(".con").load("views/startseite.html", function () {[...] });
   $("nav a").click(function (a) {
      a.preventDefault();
      a = $(this).attr("href").split("/").pop().split(".").shift();
      $(".con").hide().load("views/" + a + ".html", function () {
         $(".con").fadeIn("fast",
            function () {[...] });
      document.title = "Domain.com | " + (a.substr(0, 1).toUpperCase() + a.substr(1));
      location.hash = a;
      return !1
   })
   $(document).on('submit', 'form.ajax', function (e) {
      e.preventDefault();
      var that = $(this),
         url = that.attr('action'),
         type = that.attr('method'),
         data = {};
      that.find('[name]').each(function (index, value) {
         var that = $(this),
            name = that.attr('name'),
            value = that.val();
         data[name] = value
      });
      $.ajax({
         url: url,
         type: type,
         data: data,
         success: function () {
            $(".flipbox").flippy({
               color_target: "",
               duration: "500",
               verso: "Anything!",
               onFinish: function () {
                  $("#no-color").css("background-color", "transparent");
               }
            });
         }
      });
   });
   $(document).on('submit', 'form.lebenslauf', function (e) {
      e.preventDefault();
      var $this = $(this);
      $.ajax({
         url: './secure/secure.php',
         type: 'post',
         data: {
            code: $('input[name=bewerbung]').val()
         },
         success: function (resp) {
            if (resp.substr(0, 5) == "Error") {
               $('.error').html(resp);
            } else {
               $('.flipbox').flippy({
                  duration: "500",
                  verso: resp,
                  onFinish: function () {
                     $(".flipbox").css("background-color", "transparent");
                  }
               });
            }
         }
      });
   });
});

示例 HTML:

<ul>
    <li><a href="/views/home.html">Home</a></li>
    <li><a href="/views/about.html">About</a></li>
    <li><a href="/views/blog.html">Blog</a></li>
    <li><a href="/views/contanct.html">Contact</a></li>
</ul>

我的另一个问题是:当我想使用 'if(location.hash)' 时我需要写什么,你会把它放在哪里?使使用诸如 domain.com/about 之类的 URL 成为可能,而无需获取主站点。

4

1 回答 1

1

我不确定我们是否在同一页面上,请告诉我它是否适合您:

var path = window.location.href;
var newpath = path.replace(/[#]/g, "/");
window.location.href =newpath; 
于 2013-10-09T17:30:00.157 回答