Jquery 对不同ID使用相同值的多个变量
我正在单页应用程序上使用窗口位置和DIV IDJquery 对不同ID使用相同值的多个变量,jquery,Jquery,我正在单页应用程序上使用窗口位置和DIV IDincludecmcontent1、includecmcontent2、includecmcontent3。当满足这些条件时,外部内容将在ID处注入 但是,我发现只有3个变量中的1个触发,实际上是第一个,因为如果页面上存在includecmcontent3,则不会触发此ID,因为includecmcontent1优先 我如何解决这个问题?页面始终相同,因此值始终相同,但includecmcontent1/2/3的ID将在同一页面上交换 var TCE
includecmcontent1、includecmcontent2、includecmcontent3
。当满足这些条件时,外部内容将在ID处注入
但是,我发现只有3个变量中的1个触发,实际上是第一个,因为如果页面上存在includecmcontent3
,则不会触发此ID,因为includecmcontent1
优先
我如何解决这个问题?页面始终相同,因此值始终相同,但includecmcontent1/2/3
的ID将在同一页面上交换
var TCEApplicationNoWaiver = "TCEApplication.aspx"
var TCEApplicationWaiver = "TCEApplication.aspx"
var TCEApplicationNotEligible = "TCEApplication.aspx"
if (window.location.href.toLowerCase().indexOf(TCEApplicationNoWaiver.toLowerCase()) >= 0) {
$("#IncludeCMSContent1").load("http://www.example.com/tce-application-noWaiver.htm #externalContent");
}
else if (window.location.href.toLowerCase().indexOf(TCEApplicationWaiver.toLowerCase()) >= 0) {
$("#IncludeCMSContent2").load("http://www.example.com/tce-application-Waiver.htm #externalContent");
}
else if (window.location.href.toLowerCase().indexOf(TCEApplicationNotEligible.toLowerCase()) >= 0) {
$("#IncludeCMSContent3").load("http://www.example.com/not-eligible.htm #externalContent");
}
删除
else
语句,以便触发所有条件:
if (window.location.href.toLowerCase().indexOf(TCEApplicationNoWaiver.toLowerCase()) >= 0) {
$("#IncludeCMSContent1").load("http://www.example.com/tce-application-noWaiver.htm #externalContent");
}
if (window.location.href.toLowerCase().indexOf(TCEApplicationWaiver.toLowerCase()) >= 0) {
$("#IncludeCMSContent2").load("http://www.example.com/tce-application-Waiver.htm #externalContent");
}
if (window.location.href.toLowerCase().indexOf(TCEApplicationNotEligible.toLowerCase()) >= 0) {
$("#IncludeCMSContent3").load("http://www.example.com/not-eligible.htm #externalContent");
}
希望这有帮助。删除其他选项?您的声明目前只会触发其中一种情况