JavaScript返回特定代码中的html内容
我有以下代码:JavaScript返回特定代码中的html内容,javascript,jquery,Javascript,Jquery,我有以下代码: var currentusername = Discourse.User.currentProp('username'); if (currentusername == "crazy-geek") { api.createWidget('admin-menu', { tagName: 'div.admin-panel', panelContents() { return "hello " + currentu
var currentusername = Discourse.User.currentProp('username');
if (currentusername == "crazy-geek") {
api.createWidget('admin-menu', {
tagName: 'div.admin-panel',
panelContents() {
return "hello " + currentusername;
},
html() {
return this.attach('menu-panel', {
contents: () => this.panelContents()
});
},
clickOutside() {
this.sendWidgetAction('toggleAdmin');
}
});
api.decorateWidget('header-icons:after', function (helper) {
const headerState = helper.widget.parentWidget.state;
let contents = [];
contents.push(helper.attach('header-dropdown', {
title: 'admin-menu',
icon: 'asterisk',
active: headerState.adminVisible,
iconId: 'toggle-admin-menu',
action: 'toggleAdmin',
}));
if (headerState.adminVisible) {
contents.push(helper.attach('admin-menu'));
}
return contents;
});
api.attachWidgetAction('header', 'toggleAdmin', function () {
this.state.adminVisible = !this.state.adminVisible;
});
};
我需要在以下部分返回html内容:
panelContents() {
return "hello " + currentusername;
},
所以“hello”+currentusername部分;需要用特定的html内容替换,比如我的示例,它是一个小菜单,里面有一些链接
我如何存档它?
返回“hello”代码>只要把你想要的HTML放在那里。`return''我已经试过了,它最后向我显示:hello Test