简体   繁体   English

如何以编程方式更改 dojo/dijit 选项卡标题?

[英]How to change dojo/dijit tab title programmatically?

For example, given the dijit.ContentPane tab below, how do I programmatically change the title "Summary" to something else?例如,给定下面的 dijit.ContentPane 选项卡,我如何以编程方式将标题“摘要”更改为其他内容?

<div id="summaryContent" class="tabClass" dojoType="dijit.layout.ContentPane" title="Summary" selected="true">

I tried:我试过了:

dojo.byId('summaryContent').title
document.getElementById('summaryContent').style.title

...as well a bunch of other combinations, but it doesn't work? ...以及一堆其他组合,但它不起作用? Any ideas?有任何想法吗?

Just two small mistakes: first, to get a dijit instance (eg the dijit.layout.ContentPane javascript object, not the DOM node) you have to use dijit.byId , and secondly, setting a property on a dijit is done with the set method.只是两个小错误:首先,要获取 dijit 实例(例如 dijit.layout.ContentPane javascript object,而不是 DOM 节点),您必须使用dijit.byId ,其次,在 dijit 上设置属性是使用set方法。 So:所以:

dijit.byId("summaryContent").set("title", "My new awesome title");

.. should do the trick. ..应该做的伎俩。

This is what worked for me, not only for title but for any property:这对我有用,不仅适用于所有权,也适用于任何财产:

First include "dijit/registry" ( https://dojotoolkit.org/reference-guide/1.10/dijit/registry.html )首先包括“dijit/registry”( https://dojotoolkit.org/reference-guide/1.10/dijit/registry.html

Then in code do:然后在代码中执行:

var summaryContent = registry.byId("summaryContent");
summaryContent._set("title", "new title here");
//Set something like the icon
summaryContent._set("iconClass", "summary-icon");
  1. Get the instance of the div by using "dijit.byId".使用“dijit.byId”获取 div 的实例。
  2. As you have created the instance by using dijit ("dijit.byId"), so use the method 'set' to set the value to the property.由于您已使用 dijit ("dijit.byId") 创建了实例,因此请使用方法 'set' 将值设置为属性。

Code: dijit.byId("summaryContent").set("title", "New Title");代码: dijit.byId("summaryContent").set("title", "New Title");

*New Title : is the title which you want to set. *新标题:是您要设置的标题。

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

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