如何在mvc5中动态更改页面的背景 [英] how to change background dynamically of a page in mvc5
本文介绍了如何在mvc5中动态更改页面的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想动态更改mvc中html页面的背景。任何想法??
我有这样的特里节日
I want to change background of html page in mvc dynamically.Any idea??
I have trie like this
<script type="text/javascript">
var background = ['@Url.Content("~/Content/images/ab.jpg")',
'@Url.Content("~/Content/images/gh.jpg")',
'@Url.Content("~/Content/images/hj.jpg")',
'@Url.Content("~/Content/images/i8.jpg")'];
$(document).ready(function () {
PickRandomBackground();
});
function PickRandomBackground() {
var index = Math.floor(Math.random() * 5);
$('html').css('background-image','url('+ background[index]+')')
}
</script>
和我的.css是
and my .css is
html
{
background-image:url(images/ab.jpg);
background-repeat:repeat;
}
但它只显示ab.jpg
But it shows only ab.jpg
推荐答案
( document )。ready( function (){
PickRandomBackground();
});
function PickRandomBackground(){
var index = Math .floor( Math .random()* 5 );
(document).ready(function () { PickRandomBackground(); }); function PickRandomBackground() { var index = Math.floor(Math.random() * 5);
(' html')。css( ' background-image',' < span class =code-string> url(' + background [index] + ' )')
}
< / script>
('html').css('background-image','url('+ background[index]+')') } </script>
和我的.css是
and my .css is
html
{
background-image:url(images/ab.jpg);
background-repeat:repeat;
}
但它只显示ab.jpg
But it shows only ab.jpg
参考: MVC 4应用程序中的动态背景图像 [ ^ ]
这篇关于如何在mvc5中动态更改页面的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文