2

jQueryコードは

$(document).ready(function() {
  if (navigator.appVersion.indexOf("Win") != -1) {
   // Computers runs windows
    $("a[href$='.pdf']").each(function() {
        this.href = this.href.replace("Volumes", "KP01DS0194TG");
    });
  }
  if (navigator.appVersion.indexOf("Mac") != -1) {
    // computer is a Mac
    $("a[href$='.pdf']").each(function() {
        this.href = this.href.replace("KP01DS0194TG", "Volumes");
    });
  }
});

窓側のスラッシュを取り除くために必要ですが、どうすればよいですか?

私のリンクは次のとおりですhref="file:///KP01DS0194TG/Quotes/Scanning/brother/Jobsheets/job no 12538.pdf">12538</a>。ボリュームのあるMacの場合は問題ありませんが、PCの場合は「file:// KP01DS0194TG」として必要です。スラッシュを削除するにはどうすればよいですか?

4

1 に答える 1

3

次のようなリンクがある場合:

<a href="file:///[somelink]">Click Here</a>

スラッシュを1つ削除する場合は、次を使用します。

$('a').each(function() {
    var theLink = $(this).attr('href');// get href
    theLink = theLink.replace(/\/\/\//g,'//');// replace 3 slashes with 2
    $(this).attr('href', theLink);
});
于 2012-04-17T00:51:15.287 に答える