2015-06-26 34 views

回答

0

只是一個想法:

HTML

<div id="pageid" value="landing"> 
</div> 

JS

var page = $('#pageid').attr('value'); 
alert(page); 

這裏是fiddle

+0

而且,它怎麼能幫助我嗎?我希望它檢測頁面,如value字段中的index.html –

+0

,添加一個頁面ID /名稱或任何你喜歡區分這個頁面和其他頁面。 – Alp

0

location.href包含當前頁面的URL。因此,

if (location.href == something) { 
    // Do whatever you want 
} 

您還可以使用location.pathname來獲取URL的路徑名部分。

if (location.pathname == '/index.html') { 
    $("div").addClass("active"); 
} 

如果你不想目錄部分匹配明確,你可以寫:

if (location.pathname.indexOf('pluginview.html') != -1) { 
    $("#pluginviewbody").hide(); 
} 
+0

@LoganMaster在這種情況下沒有區別。 – Barmar

+0

'location.pathname'是整個路徑,包括所有的目錄前綴。 – Barmar

+0

'console.log(location.pathname)'show? – Barmar

相關問題