当选择选项选项时,Javascript显示隐藏的div错误

时间:2016-04-18 15:51:03

标签: javascript css select hide show

我试图将this code用于更复杂的选择列表,但似乎无法正常工作。

如果选择value = 0,则应显示隐藏的div。 如果选择value = 1,则应显示另一个隐藏的div。

我是JS的新手。你能帮忙找到错误吗?

HTML:



<select name="status" id="soflow2" onchange="showDiv(this)">
<option>Select</option>  
<option value="0">Single</option>
<option value="1">Married</option>
<option value="1">Registered Legal Partnership</option>
<option value="1">Remarried</option>
<option value="0">Legally Separated</option>
<option value="0">Divorced</option>
<option value="0">Widowed</option>
<option value="1">Informal Partnership</option>
</select>

<div id="stepsHIDDEN">
<button type="button" class="nextstep"><a href="04Step.html">Next</a></button>
</div>

<div id="questionHIDDEN">
<p>
Is your spouse gainfully employed?
</p>
</div>
&#13;
&#13;
&#13;

JS:

&#13;
&#13;
function showDiv(elem){
if(elem.value == 1)
document.getElementById('hidden_div').style.display = "block";
} else { document.getElementById('stepsHIDDEN').style.display = "block";
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

默认情况下,未明确拥有值的DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/api/guest/1'; against '/api/guest/**' DEBUG org.springframework.security.web.FilterChainProxy - /api/guest/1 at position 1 of 4 in additional filter chain; firing Filter: 'GrailsAnonymousAuthenticationFilter' INFO org.springframework.security.core.SpringSecurityCoreVersion - You are running with Spring Security Core 4.0.3.RELEASE DEBUG grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter - Populated SecurityContextHolder with anonymous token: 'grails.plugin.springsecurity.authentication.GrailsAnonymousAuthenticationToken@dc41564: Principal: org.springframework.security.core.userdetails.User@dc730200: Username: __grails.anonymous.user__; Password: [PROTECTED]; Enabled: false; AccountNonExpired: false; credentialsNonExpired: false; AccountNonLocked: false; Granted Authorities: ROLE_ANONYMOUS; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS' DEBUG org.springframework.security.web.FilterChainProxy - /api/guest/1 at position 2 of 4 in additional filter chain; firing Filter: 'RestTokenValidationFilter' DEBUG grails.plugin.springsecurity.rest.token.bearer.BearerTokenReader - Looking for bearer token in Authorization header, query string or Form-Encoded body parameter DEBUG grails.plugin.springsecurity.rest.token.bearer.BearerTokenReader - No token found DEBUG grails.plugin.springsecurity.rest.token.bearer.BearerTokenReader - Token: null DEBUG grails.plugin.springsecurity.rest.RestTokenValidationFilter - Token not found DEBUG grails.plugin.springsecurity.rest.RestTokenValidationFilter - Request does not contain any token. Letting it continue through the filter chain DEBUG org.springframework.security.web.FilterChainProxy - /api/guest/1 at position 3 of 4 in additional filter chain; firing Filter: 'ExceptionTranslationFilter' DEBUG org.springframework.security.web.FilterChainProxy - /api/guest/1 at position 4 of 4 in additional filter chain; firing Filter: 'FilterSecurityInterceptor' DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - Secure object: FilterInvocation: URL: /api/guest/1; Attributes: [_DENY_] DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - Previously Authenticated: grails.plugin.springsecurity.authentication.GrailsAnonymousAuthenticationToken@dc41564: Principal: org.springframework.security.core.userdetails.User@dc730200: Username: __grails.anonymous.user__; Password: [PROTECTED]; Enabled: false; AccountNonExpired: false; credentialsNonExpired: false; AccountNonLocked: false; Granted Authorities: ROLE_ANONYMOUS; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS DEBUG org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl - getReachableGrantedAuthorities() - From the roles [ROLE_ANONYMOUS] one can reach [ROLE_ANONYMOUS] in zero or more steps. DEBUG org.springframework.security.web.access.ExceptionTranslationFilter - Access is denied (user is anonymous); redirecting to authentication entry point org.springframework.security.access.AccessDeniedException: Access is denied at org.springframework.security.access.vote.AbstractAccessDecisionManager.checkAllowIfAllAbstainDecisions(AbstractAccessDecisionManager.java:70) at grails.plugin.springsecurity.access.vote.AuthenticatedVetoableDecisionManager.decide(AuthenticatedVetoableDecisionManager.groovy:50) at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:232) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:123) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at javax.servlet.FilterChain$doFilter.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) at grails.plugin.springsecurity.rest.RestTokenValidationFilter.processFilterChain(RestTokenValidationFilter.groovy:122) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:190) at grails.plugin.springsecurity.rest.RestTokenValidationFilter.doFilter(RestTokenValidationFilter.groovy:90) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.groovy:53) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:73) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:103) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) DEBUG org.springframework.security.web.access.ExceptionTranslationFilter - Calling Authentication entry point. DEBUG grails.plugin.springsecurity.rest.token.bearer.BearerTokenReader - Looking for bearer token in Authorization header, query string or Form-Encoded body parameter DEBUG grails.plugin.springsecurity.rest.token.bearer.BearerTokenReader - No token found DEBUG grails.plugin.springsecurity.rest.token.bearer.BearerTokenReader - Token: null DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/error'; against '/api/guest/**' DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/error'; against '/api/**' DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher - Request '/error' matched by universal pattern '/**' DEBUG org.springframework.security.web.FilterChainProxy - /error at position 1 of 10 in additional filter chain; firing Filter: 'SecurityRequestHolderFilter' DEBUG org.springframework.security.web.FilterChainProxy - /error at position 2 of 10 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter' DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository - No HttpSession currently exists DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository - No SecurityContext was available from the HttpSession: null. A new one will be created. DEBUG org.springframework.security.web.FilterChainProxy - /error at position 3 of 10 in additional filter chain; firing Filter: 'MutableLogoutFilter' DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher - Checking match of request : '/error'; against '/logoff' DEBUG org.springframework.security.web.FilterChainProxy - /error at position 4 of 10 in additional filter chain; firing Filter: 'GrailsUsernamePasswordAuthenticationFilter' DEBUG org.springframework.security.web.FilterChainProxy - /error at position 5 of 10 in additional filter chain; firing Filter: 'RestAuthenticationFilter' DEBUG grails.plugin.springsecurity.rest.RestAuthenticationFilter - Actual URI is /error; endpoint URL is /api/login DEBUG org.springframework.security.web.FilterChainProxy - /error at position 6 of 10 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter' DEBUG org.springframework.security.web.FilterChainProxy - /error at position 7 of 10 in additional filter chain; firing Filter: 'GrailsRememberMeAuthenticationFilter' DEBUG org.springframework.security.web.FilterChainProxy - /error at position 8 of 10 in additional filter chain; firing Filter: 'GrailsAnonymousAuthenticationFilter' DEBUG grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter - Populated SecurityContextHolder with anonymous token: 'grails.plugin.springsecurity.authentication.GrailsAnonymousAuthenticationToken@dc41564: Principal: org.springframework.security.core.userdetails.User@dc730200: Username: __grails.anonymous.user__; Password: [PROTECTED]; Enabled: false; AccountNonExpired: false; credentialsNonExpired: false; AccountNonLocked: false; Granted Authorities: ROLE_ANONYMOUS; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS' DEBUG org.springframework.security.web.FilterChainProxy - /error at position 9 of 10 in additional filter chain; firing Filter: 'ExceptionTranslationFilter' DEBUG org.springframework.security.web.FilterChainProxy - /error at position 10 of 10 in additional filter chain; firing Filter: 'FilterSecurityInterceptor' DEBUG org.springframework.security.web.FilterChainProxy - /error reached end of additional filter chain; proceeding with original chain DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession. DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository$SaveToSessionResponseWrapper - Skip invoking on DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository$SaveToSessionResponseWrapper - Skip invoking on DEBUG org.springframework.security.web.context.HttpSessionSecurityContextRepository$SaveToSessionResponseWrapper - Skip invoking on DEBUG org.springframework.security.web.access.ExceptionTranslationFilter - Chain processed normally DEBUG org.springframework.security.web.context.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed 会尝试使用该文本,因此当您没有选择时,<option>属性将会be&#34;选择&#34;。

您可以使用它来相应地显示或隐藏或value

<div>

或者如果您更喜欢使用单线功能:

<!-- You may want to initially hide your section since it won't have a value -->
<div id="stepsHIDDEN" style='display:none;'>
    <button type="button" class="nextstep">
        <a href="04Step.html">Next</a>
    </button>
</div>
<script>
    function showDiv(elem){
        // If your value is `Select`, then hide your element
        if(elem.value == 'Select'){
            document.getElementById('stepsHIDDEN').style.display = "none";
        } 
        else{ 
            document.getElementById('stepsHIDDEN').style.display = "block";
        }
    }
</script>

完成示例

enter image description here

&#13;
&#13;
function showDiv(elem){
   document.getElementById('stepsHIDDEN').style.display = (elem.value == 'Select') ? "none" : "block";      
}
&#13;
&#13;
&#13;