【问题标题】:Is there a way to overwrite the values of a dynamically created html elements created by a Sencha app?有没有办法覆盖由 Sencha 应用程序创建的动态创建的 html 元素的值?
【发布时间】:2022-12-20 03:47:51
【问题描述】:

我目前正在开发一个使用 Sencha 作为前端的项目。我想将类值(并且可能添加 ID 值)更改为 Sencha 创建的 HTML 元素。有没有办法使用 Sencha 代码实现此目的?例如,Sencha 动态创建这个 div 元素:

<div unselectable="on" class="x-grid-cell-inner" style="text-align:left;">Name</div>

我的问题是这些由 Sencha 创建的 HTML 元素是否可以被覆盖。如果没有,还有其他方法可以实现吗? 感谢您的帮助,伙计们!

我的想法是使用一些 Sencha 代码覆盖类名,这样类值就变成 class="block draggable",这会从外部 JavaScript 和 CSS 库 (https://github.com/TobiasKoller/tko.flowchartdesigner) 解锁一些想要的功能。截至目前,我已尝试使用以下代码,但它不起作用(元素类值保持不变):

var module = new Ext.Element(document.getElementsByClassName('x-grid-cell-inner'));
module.addCls('block draggable');

【问题讨论】:

    标签: javascript html css extjs sencha-touch


    【解决方案1】:

    您可以通过调用 div 元素上的 setAttribute 方法并将新类值作为参数传递来更改类值:

    var element = document.getElementsByClassName('x-grid-cell-inner')[0]; // Get the first element with the specified class name
    element.setAttribute('class', 'block draggable'); // Set the class attribute to the new value
    

    或者,您可以使用 className 属性来设置类值。这是您如何做到这一点的示例:

    var element = document.getElementsByClassName('x-grid-cell-inner')[0]; // Get the first element with the specified class name
    element.className = 'block draggable'; // Set the className property to the new value
    

    我希望这有帮助!

    【讨论】:

      猜你喜欢
      • 2011-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-29
      相关资源
      最近更新 更多