【问题标题】:Struts 2 select readonly propertyStruts 2 选择只读属性
【发布时间】:2020-12-04 15:01:39
【问题描述】:

我需要将<s:select> 下拉值设置为只读。但是由于<s:select> 仅具有禁用属性,如何使<s:select> 表现为只读。我直接把readonly放在<s:select>上,但是没有用。

【问题讨论】:

  • 只读<s:select>?你想达到什么目标?
  • 为什么disabled="true" 对你想要的无效?当我需要它时,我就是这样做的。
  • 禁用的表单项不会发送到浏览器。要么将值也保留在隐藏字段中,要么对后端进行编码以便不需要该值。

标签: java html jsp struts2


【解决方案1】:

看起来像放置一个 HTML 属性 contenteditable="true" 使其表现得像只读。这种方式你无法从下拉列表中选择值。

【讨论】:

  • 请告诉我这是否适用于 chrome 或 Internet Explorer,因为它不适用于我请帮助我
【解决方案2】:

你可以写一些CSS,然后放一个HTML属性readonly="true"

 /*Select2 ReadOnly Start*/
    select[readonly].select2-hidden-accessible + .select2-container {
        pointer-events: none;
        touch-action: none;
    }
    
    select[readonly].select2-hidden-accessible + .select2-container .select2-selection {
        background: #eee;
        box-shadow: none;
    }
    
    select[readonly].select2-hidden-accessible + .select2-container .select2-selection__arrow, select[readonly].select2-hidden-accessible + .select2-container .select2-selection__clear {
        display: none;
    }
    
    /*Select2 ReadOnly End*/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    相关资源
    最近更新 更多