Displaying Radio Button Options in Different Colors by JS

  • Last update:December 16, 2025
  • Overview

    Application Scenario

    After setting the data dictionary for the radio button widget, the display effect is relatively monotonous. Is there any way to assign different colors to each option, making the overall look more beautiful and layered?

    1.1应用场景.png

    Implementation Effect

    You can use HTML tags to achieve the effect, as shown in the following figure.

    1.2实现效果.png

    Example

    Report Design

    The cell design is as follows. Insert a radio button group widget in cell B2.

    2.1设计报表.png

    Data Dictionary Setting

    Select cell B2, and set the data dictionary (set Type to Formula).

    iconNote:

    In actual use, you can set Type to Database Table or Data Query as required. However, Display Value needs to be set to Formula.

    Actual Value: ["Apple","Banana","Durian"]

    Display Value: "<span style='color:#fff;padding:1px 5px;border-radius:10px;background-color:" + switch($$$,"Apple","red","Banana","#f5c13c","Durian","green") + "'>" + $$$ + "</span>"

    Parsing of HTML attributes in Display Value:

    Attribute SettingDescription

    color:#fff

    Text color: white

    padding:1px 5px

    Top and bottom padding:1 px; left and right padding: 5 px

    border-radius:10px

    Shape: rounded corner with a radius of 10 px

    background-color:red

    Setting the background color of the span tags according to the values calculated by the formula switch($$$,"Apple","red","Banana","#f5c13c","Durian","green")

    2.2 设置数据字典.png


    iconNote:
    There is no need to set Display Content to Display by HTML, however, such a setting is not wrong.

    Effect Preview

    Click Save, and click Data Entry Preview. The following figure shows the effect.

    PC:

    PC端.png

    iconNote:

    The effect cannot be previewed on mobile terminals.

    Template Download

    Attachment List


    Theme: Data Entry
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy