Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript返回特定代码中的html内容_Javascript_Jquery - Fatal编程技术网

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