css覆盖JavaScript [英] css Override JavaScript
问题描述
我有一个内联Css:
I have a Inline Css:
<style type="text/css">
body
{
background-color:Black;
}
</style>
和一个java脚本:
< script type =text / javascript>
函数SetValue()
{
document.getElementById(''HiddenField1'')。value =red ;
document.bgColor = document.getElementById(''HiddenField1'')。value;
}
< / script>
我称这个Java脚本为
< body onload = SetValue();>
但我的问题是,
我的页面颜色样式表,
如果我删除Css然后我的页面将颜色带到java脚本,
所以我希望我的页面包含Css和Java脚本,
和我的页面颜色为java脚本,
我该怎么办?这个
And A java script:
<script type="text/javascript">
function SetValue()
{
document.getElementById(''HiddenField1'').value = "red";
document.bgColor = document.getElementById(''HiddenField1'').value;
}
</script>
And I call this Java script Like
<body onload="SetValue();">
But my Problem Is,
That My Page take colour Of Style Sheet,
And If i remove Css Then My page take colour to java script,
so i want that my page contain both Css And Java Script,
and my page take colour to java script,
how can i do this
推荐答案
你可以尝试用下面的代码替换代码行,看看它是否有效
Can you try replacing your code line with the below and see if it works
document.body.style.backgroundColor = document.getElementById('HiddenField1').value;
如果不起作用,那么尝试使用像样本一样的jquery下面
if that doesnt work, then try using jquery like the sample below
(' body')。css(' background',' #ccc');
('body').css('background', '#ccc');
这篇关于css覆盖JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!