如果url包含#,则不执行脚本

我只想在url不包含的情况下执行下面的脚本#

因此,如果url = http://win-e98sopqc735/Previsions/Lists/Prvisions/ViewParDateJour.aspx#ServerFilter=FilterField1,请不要执行脚本

但如果url = http://win-e98sopqc735/Previsions/Lists/Prvisions/ViewParDateJour.aspx则执行

function addDays(dateObj, numDays) { dateObj.setDate(dateObj.getDate() + numDays); return dateObj; } function dateToShortString(date) { var d = date.getDate(); var days = (d < 10) ? '0' + d : d; var m = date.getMonth() + 1; var month = (m = 0 || url.indexOf('ViewParDateJour.aspx') >= 0) { jQuery("input[id*='ctl00_ctl00_ctl00']").val(today); jQuery("input[id*='ctl00_ctl01_ctl00']").val(today); } //Set tomorrow's date if url contains ViewParDateDemain.aspx and ViewParRubriqueDemain.aspx if (url.indexOf('ViewParDateDemain.aspx') >= 0 || url.indexOf('ViewParRubriqueDemain.aspx') >= 0) { jQuery("input[id*='ctl00_ctl00_ctl00']").val(tomorrow); jQuery("input[id*='ctl00_ctl01_ctl00']").val(tomorrow); } //Set 7 days date if url contains ViewParDate7.aspx and ViewParRubrique7.aspx if (url.indexOf('ViewParDate7.aspx') >= 0 || url.indexOf('ViewParRubrique7.aspx') >= 0) { jQuery("input[id*='ctl00_ctl00_ctl00']").val(tomorrow); jQuery("input[id*='ctl00_ctl01_ctl00']").val(nextWeek); } 

以下代码查找url中的任何哈希。

 if (!window.location.hash) { // there is no hash, so execute stuff } 

如果要查找特定哈希,请使用:

 if (!window.location.hash == "specific-hash") { // execute stuff } 

检查window.location.hash ,如果没有设置哈希,它将是#ServerFilter=FilterField1或空字符串。

请注意,只有在#标签后面有内容时才会有效。 如果只有一个hashtag,你将不得不解析window.location

 function addDays(dateObj, numDays) { if(window.location.href.indexOf('#')) return; // this will stop the script dateObj.setDate(dateObj.getDate() + numDays); return dateObj; } function dateToShortString(date) { var d = date.getDate(); var days = (d < 10) ? '0' + d : d; var m = date.getMonth() + 1; var month = (m < 10) ? '0' + m : m; var year = date.getFullYear(); var shortDateString = days + "/" + month + "/" + year; return shortDateString; } .... ....