开发者

Getting an update script to work and adding style sheets

I tried making thi开发者_如何学Pythons script to update content work, but my quotes aren't showing up at all. Additionally, I'll need to add some CCS to the quotes themselves. I need help trouble shooting the code. Here's a link to the original question, and I'm attaching the code in the way that i implemented it.

jQuery: update content every week (or long period of time)

update-content.html:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="quotes.js">
</head>
<body>
<div id="quotes-wrapper" class="quote-29">
  <div class="quote">Testimonial Week 29</div>
  <div class="author">Author</div>
</div>
<div id="quotes-wrapper" class="quote-30">
    <div class="quote">Testimonial Week 30</div>
    <div class="author">Author</div>
</div>
<div id="quotes-wrapper" class="quote-31">
    <div class="quote">Testimonial Week 31</div>
    <div class="author">Author</div>
</div>
</body>

quotes.js:

Date.prototype.getWeek = function() {
var onejan = new Date(this.getFullYear(),0,1);
return Math.ceiling((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
}

$(function(){
    var today = new Date();
    var weekno = today.getWeek();
    $('#quotes-wrapper').load('update-content.html div.quote-'+weekno);
});


here is your error

<script type="text/javascript" src="quotes.js">

should be

<script type="text/javascript" src="quotes.js"></script>

also you are missing the jquery library, which should be added before your script.


Two problems jump out at me:

  1. You've given all three div elements the same id as id="quotes-wrapper" - id is supposed to be unique, so when you use it as a selector I would expect jQuery to just find the first one. Given the rest of your HTML you might want to give jQuery a selector based on the class rather than the id.

  2. The URL passed to the load() function in this code:

$('#quotes-wrapper').load('update-content.html div.quote-'+weekno);

doesn't seem right. You've got a space after .html where I would expect a ? and one or more parameters.

So taking the above two points I'd expect something more like:

$('div.quote-'+weekno).load('update-content.html?someParam='+weekno);

or

$('#someuniqueid').load('update-content.html?someParam='+weekno);

Also you need a closing </script> tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜