2

以下のjQueryは機能しませんが、var linkそれと等しい場合は、IFが指定された変数で終わるfile:///C:/Users/USER/Desktop/test%20page/Home.htmljqueryがあり、javascriptを実行します。window.location.href;var link ="/Home.html";

$(document).ready(function(){
var winloc = window.location.href; // file:///C:/Users/USER/Desktop/test%20page/Home.html
var link = "/Home.html";
if(winloc==link){
$('ul li a').remove();
}
});
<ul>
<li><a href="Home.html">Home</a></li>
</ul>
4

3 に答える 3

1

あなたの場合lastIndexOfのURLの最後の部分を使用して取得し、 varで確認します。/Home.htmllink

私のデモを参照してください。

以下のコード、

$(document).ready(function() {
    var winloc = "file:///C:/Users/USER/Desktop/test%20page/Home.html";
    var link = "/Home.html";
    winloc = winloc.substring (winloc.lastIndexOf("/"));
    if (winloc == link) {
        $('ul li a').remove();
    }
});
于 2012-02-13T22:46:40.517 に答える
0
if( winloc.substr(winloc.length-link.length) == link) {
    $('ul li a').remove();
}
于 2012-02-13T22:39:59.693 に答える
0

これは、Jivings が書くつもりだったと私が考える 1 つのライナーです。受け入れられているソリューションhttp://jsfiddle.net/mendesjuan/qbcpm/10/よりもエレガントだと思います

$(document).ready(function() {
    var winloc = "file:///C:/Users/USER/Desktop/test%20page/Home.html";
    // The regular expression below looks for Home.html at the end of a string 
    if (/Home\.html$/.test(winloc)) {
        $('ul li a').remove();
    }
});
于 2012-02-14T00:59:00.630 に答える