我有这段代码,我正在生成随机颜色并将其转换为十六进制,然后我想将其设置为 backgroundColor
的 .ribbon a:hover
跨度类:
<script type="text/javascript">
$(function() {
var randomColor = Math.floor(Math.random()*16777215).toString(16);
alert(randomColor);
$(".ribbon a:hover span").css({
backgroundColor: '#' + randomColor
});
});
</script>
这是我的CSS:
.ribbon a:hover span {
background: /*<?php printf( "#%06X\n", mt_rand( 0, 0xFFFFFF )); ?>*/ #FFF;
margin-top:0;
}
它甚至不会提醒我的 randomColor 变量...我已将此脚本放在 </body>
之前标记...
最佳答案
jQueryUI 不包含 jQuery:您仍然需要加载它(之前)。
所以你应该替换
<script src="http://www.google.com/jsapi"></script>
<!-- load JQuery and UI from Google (need to use UI to animate colors) -->
<script type="text/javascript"> google.load("jqueryui", "1.5.2"); </script>
与
<script src="http://www.google.com/jsapi"></script> <!-- load JQuery and UI from Google (need to use UI to animate colors) -->
<script type="text/javascript">
google.load("jquery", "1.5.2");
google.load("jqueryui", "1.5.2");
</script>
关于jQuery 随机颜色 - 悬停时设置不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13535828/