Javascript 基于当前URL生成if语句(不指定)
所以,我基本上是基于当前的URL来显示特定的RSS提要。下面的解决方案在某种程度上实现了这一点,但我不想在变量中指定URL,而是检查当前URL,如果它包含,则执行/拉入我的rss提要。Javascript 基于当前URL生成if语句(不指定),javascript,jquery,Javascript,Jquery,所以,我基本上是基于当前的URL来显示特定的RSS提要。下面的解决方案在某种程度上实现了这一点,但我不想在变量中指定URL,而是检查当前URL,如果它包含,则执行/拉入我的rss提要。 下面的解决方案无法工作,因为我需要对多个URL进行多次检查 jQuery(function($) { // display rss feed based on current URL // start conditions to display 3 feeds on different URLs var
下面的解决方案无法工作,因为我需要对多个URL进行多次检查
jQuery(function($) { // display rss feed based on current URL
// start conditions to display 3 feeds on different URLs
var url = 'http://localhost:8888/';
if (url.indexOf('8888') > -1) {
$(".feed1").rss("http://www.thehollywoodgossip.com/rss.xml",
{
limit: 17,
entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>'
})
$(".feed2").rss("http://www.thehollywoodgossip.com/rss.xml",
{
limit: 17,
entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>'
})
$(".feed3").rss("http://www.thehollywoodgossip.com/rss.xml",
{
limit: 17,
entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>'
})
}
if (url.indexOf('movies') > -1) {
$(".feed1").rss("http://www.thehollywoodgossip.com/rss.xml",
{
limit: 17,
entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>'
})
$(".feed2").rss("http://www.thehollywoodgossip.com/rss.xml",
{
limit: 17,
entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>'
})
$(".feed3").rss("http://www.thehollywoodgossip.com/rss.xml",
{
limit: 17,
entryTemplate:'<h1 class="feedtitle"><a href="{url}">[{author}@{date}] {title}</a></h1><br/><div class="featimg">{teaserImage}</div><div class="feedtxt">{shortBodyPlain}</div>'
})
}
.......
jQuery(函数($){//基于当前URL显示rss提要
//在不同URL上显示3个提要的开始条件
var url='1〕http://localhost:8888/';
如果(url.indexOf('8888')>-1){
$(“.feed1”).rss(”http://www.thehollywoodgossip.com/rss.xml",
{
限额:17,
entryTemplate:“
{teaserImage}{shortBodyPlain}”
})
$(“.feed2”).rss(”http://www.thehollywoodgossip.com/rss.xml",
{
限额:17,
entryTemplate:“
{teaserImage}{shortBodyPlain}”
})
$(“.feed3”).rss(”http://www.thehollywoodgossip.com/rss.xml",
{
限额:17,
entryTemplate:“
{teaserImage}{shortBodyPlain}”
})
}
如果(url.indexOf('movies')>-1){
$(“.feed1”).rss(”http://www.thehollywoodgossip.com/rss.xml",
{
限额:17,
entryTemplate:“
{teaserImage}{shortBodyPlain}”
})
$(“.feed2”).rss(”http://www.thehollywoodgossip.com/rss.xml",
{
限额:17,
entryTemplate:“
{teaserImage}{shortBodyPlain}”
})
$(“.feed3”).rss(”http://www.thehollywoodgossip.com/rss.xml",
{
限额:17,
entryTemplate:“
{teaserImage}{shortBodyPlain}”
})
}
.......
请注意,提要URL将不同。这只是一个示例。而不是
var url = 'http://localhost:8888/';
做
这是关于如何检查当前URL的问题吗?
var url = window.location.href;