我在 ASP.NET 中有以下代码,每次用户进入登录页面时调用随机图像。它在 Internet Explorer 中运行良好,但在其他浏览器中运行不佳。我缺少什么?
<head runat="server">
<title>Login</title>
<link href="css/reset.css" rel="stylesheet" />
<link href="css/default.css" rel="stylesheet" />
<link href='http://fonts.googleapis.com/css?family=Carrois+Gothic' rel='stylesheet' type='text/css'/>
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui-1.10.3.custom.min.js"></script>
<script src="development-bundle/ui/jquery.ui.button.js"></script>
<script type="text/javascript">
$(function () {
$('input:submit, input:reset').each(function () {
$(this).replaceWith('<button type="submit" name="' + $(this).attr('name') + '" class="' + $(this).attr('class') + '" id="' + $(this).attr('id') + '" >' + $(this).val() + '</button>');
});
$("input:button, a, button", ".page").button();
$("a", ".demo").click(function () { return false; });
var images = ['image1.jpg', 'image2.jpg', 'image3.jpg', 'image4.jpg', 'image5.jpg', 'image6.jpg', 'image7.jpg', 'image8.jpg'];
$('body').css({ 'background': 'url(img/loginBackground/' + images[Math.floor(Math.random() * images.length)] + ') no-repeat fixed 100% 100%;' });
});
</script>
使用此代码无法解决我的问题。它不允许我在 Internet Explorer 或其他浏览器上看到背景:
$("body").css({ 'background-image': 'url(img/loginBackground/' + images[Math.floor(Math.random() * images.length)] + ')'});
$("body").css({'background-repeat':'no repeat'});
$("body").css({'background-size':'100% 100%'});
最佳答案
在单独的行中设置正文的样式。
试试这个:
var images = ['them1.png', 'them2.png', 'them3.png', 'them4.png'];
$("body").css({ 'background-image': 'url(skins/' +
images[Math.floor(Math.random() * images.length)] + ')'});
$("body").css({'backgroundRepeat':'no repeat'});
$("body").css({'backgroundSize':'100% 100%'});
关于c# - 每次访问登录表单时 ASP.NET 中的随机图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18230268/