这是我正在网页上尝试的功能。
我希望第二个按钮在鼠标指针位于其上时更改背景颜色(黑色),并在其离开时更改为原始颜色(红色)。我以按钮为例,但是如果您注意到的很好,该按钮是由svg代码制成的,它还有其他用途。
我能够实现第一步(悬停功能),但是我的代码(悬停功能)不起作用。
我在哪里错了?
代码:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'parentController': Unsatisfied dependency expressed through field 'parentRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'parentRepository': Post-processing of merged bean definition failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.PersistenceContext.synchronization()Ljavax/persistence/SynchronizationType;
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1350) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:580) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at soft.eng.project.SoftEngApplication.main(SoftEngApplication.java:10) [classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'parentRepository': Post-processing of merged bean definition failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.PersistenceContext.synchronization()Ljavax/persistence/SynchronizationType;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:558) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
... 19 common frames omitted
Caused by: java.lang.NoSuchMethodError: javax.persistence.PersistenceContext.synchronization()Ljavax/persistence/SynchronizationType;
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.<init>(PersistenceAnnotationBeanPostProcessor.java:653) ~[spring-orm-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.lambda$buildPersistenceMetadata$1(PersistenceAnnotationBeanPostProcessor.java:435) ~[spring-orm-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:522) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.buildPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:420) ~[spring-orm-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:394) ~[spring-orm-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:332) ~[spring-orm-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1022) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
... 28 common frames omitted
function showbut(btndiv, fillcolormask, fillcolortext, btntxt) {
document.getElementById(btndiv).innerHTML = btntxt;
var btndivv = document.getElementById(btndiv).innerHTML;
var btndivvcpy = btndivv;
var idx = btndivv.replace(/\<br\>/g, "*");
var idxArr = idx.split("*");
var idxArrlen = idxArr.length;
var offset = document.getElementById(btndiv).offsetWidth;
var wdth = parseInt(offset + 36);
var hght = 30;
for (var i = 0; i < idx.length; i++) {
var chrt = idx.substring(i, i + 1);
//alert(chrt);
if (chrt === "*") {
hght = hght + 20;
}
}
var bouton = "<svg width='" + wdth + "px' height='" + hght + "px' viewBox='0 0 " + wdth + " " + hght + "' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>";
bouton = bouton + "<title>un bouton</title>";
//alert(bouton);
bouton = bouton + "<desc>Created with Sketch.</desc>";
bouton = bouton + "<defs>";
bouton = bouton + " <rect id='path-1" + btndivv + "' x='0' y='0' width='" + wdth + "' height='" + hght + "' rx='15'></rect>";
bouton = bouton + "</defs>";
bouton = bouton + "<g id='Page-1" + btndivv + "' stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'>";
bouton = bouton + " <g id='" + btndivv + "'>";
bouton = bouton + " <mask id='mask-2" + btndivv + "' fill='white'>";
bouton = bouton + " <use xlink:href='#path-1" + btndivv + "'></use>";
bouton = bouton + " </mask>";
bouton = bouton + " <use id='Mask" + btndivv + "' fill='" + fillcolormask + "' xlink:href='#path-1" + btndivv + "'></use>";
bouton = bouton + " <text mask='url(#mask-2" + btndivv + ")' font-family='Helvetica-Bold, Helvetica' font-size='13' font-weight='bold' fill='" + fillcolortext + "'>";
bouton = bouton + " <tspan x='18' y='18'>" + idxArr[0] + "</tspan>";
var y = 18;
for (var i = 1; i < idxArrlen; i++) {
var y = y + 18;
bouton = bouton + " <tspan x='18' y='" + y + "' >" + idxArr[i] + "</tspan>";
offset = idxArr[i].length;
}
bouton = bouton + " </text>";
bouton = bouton + " </g>";
bouton = bouton + " </g>";
bouton = bouton + "</svg>";
document.getElementById(btndiv).innerHTML = bouton;
return false;
}
var btdiv1txt = "un bouton";
var btdiv2txt = "un bouton de la rue";
var btdiv3txt = "un bouton de la rue un peu <br> lourdement siture <br> au niveau de la taille. <br>poincarre a vu son prix se delabrer jusqu'a devenir poussiere";
document.getElementById("btdiv2").addEventListener("mouseout", outhover, false);
document.getElementById("btdiv2").addEventListener("mouseover", inhover, false);
var a = showbut("btdiv1", "#D8D8D8", "#D0011B", btdiv1txt);
var b = showbut("btdiv2", "#D7073F", "#FFFFFF", btdiv2txt);
var c = showbut("btdiv3", "#D8D8D8", "#D0011B", btdiv3txt);
function inhover() {
var btdiv22txt = btdiv2txt;
var k = showbut("btdiv2", "#000000", "#FFFFFF", btdiv22txt);
return false;
}
function outhover() {
var y = showbut("btdiv2", "#D7073F", "#FFFFFF", btdiv2txt);
return false;
}
答案 0 :(得分:3)
可以在CSS中而不是在javascript中设置样式吗?如果是这样,它应该像执行以下操作一样简单:
#btn2{
background-color:black;
color:white
}
#btn2:hover{
background-color: red;
}
<button id="btn2">
Button 2
</button>