基本上,如果我在:http://example.com/content/connect/152,我想知道url中是否存在「connect」,然後將菜單的選定值設置爲具體的事情......(url也可以像http://example.com/content/connections,在這種情況下,它仍然應該匹配...)jquery - 嘗試使用與window.location.pathname的模式匹配
這是我一直很努力,這,顯然是不工作... 。
var path = window.location.pathname;
if(path).match(/^connect) {
$("#myselect").val('9');
} else {
$("#myselect").val('0');
}
我想你只是在if中有一個錯字。不應該是如果(path.match(/^connect))? – 2009-12-18 19:24:31