I want to set page backgroudImage using jQuery.
I wrote this code but it is not work. What is the problem? Image is existvar Page = $(this);
$(function () {
SetBackgroundImage();
});
function SetBackgroundImage() {
//Todo read ImagePath from ser开发者_JAVA技巧ver
var ImageUrl;
ImageUrl ="../Images/BackgroudImage.jpg";
try {
Page.css('background-image', 'url(' + ImageUrl + ')');
} catch (e) {
//LogError
alert(e.Description);
}
}
The variable Page
currently holds a reference to a jQuery object which is wrappend around the window
element. You'll want the jQuery object to wrap around the body
tag.
To retrieve the body element you'll have to adjust your code a bit, like so:
$(function() {
$('body').css('background-image', 'url(' + ImageUrl + ')');
});
I suggest you take a look at the jQuery API for some more information about jQuery.
精彩评论