繁体   English   中英

使用Java启用/禁用按钮

[英]Enabling/Disabling button with Javascript

问题:我在VisualForce页面上有一个apex:commandButton,并且其中包含一些逻辑的js文件。 当前,此逻辑使用CSS影响按钮在页面上是可见还是不可见。 我需要更改此设置,以使其启用或禁用按钮。 但是,每当我尝试禁用js文件中的按钮时,屏幕上的按钮都不会受到影响。 我对前端开发人员没有经验,因此可能会丢失或误解一些明显的东西。

.page文件上的按钮:

    <apex:commandButton id="commitButton"
        action="{!commitSelectedLines}"
        value="{!$Label.commitSelectedLines}"/>

.js文件(已大幅度地修改为看似相关的位):

FFDCBalancer = (function(){

    /**
     * Singleton Balancer object to maintain balances on the page.
     */
    var balancer = {

        /** JQuery button component for the commit button. */
        cmdCommit: undefined,

        /** Set the enabled-ness of the commit button. */
        setCommitEnabled : function(value) {
            //I PRESUMABLY NEED TO CHANGE THIS BIT TO USE 'DISABLED'.
            this.cmdCommit.css({
               'display': value ? 'block' : 'none'
            });

            //I HAVE TRIED VARIOUS BITS OF CODE, SUCH AS THIS
            //this.cmdCommit.disabled = value;

        },

        /**
         * Respond to refresh by connecting event handlers and calculating the balances.
         */
        onRefresh : function () {
            var me = this;
            me.cmdCommit = $FFDC('#commitButton');
        }
    };

    $FFDC(document).on('FFDCRefresh', function(){ balancer.onRefresh(); });
    return balancer;
}());

为此,您可以执行以下两项操作之一:

  1. 使用{!$ Component ... commitButton}来获取客户端ID,尽管它确实会使JQuery混乱,因为它在ID之间添加了一个冒号,因此您必须将其与document.getElementById结合使用(...) - 例如:

    jQuery(document.getElementById('{!$Component.Form.commitButton}')).attr('disabled','disabled');

  2. 在按钮上放置一个“ styleClass”,并使用该样式进行更改:

    <apex:commandButton id="commitButton" action="{!commitSelectedLines}" value="{!$Label.commitSelectedLines}" styleClass="commitButtonClass" />

然后使用jQuery设置属性:

jQuery(".commitButtonClass").attr('disabled','disabled');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM