如何使用<SELECT>MODEL TINYNCE WindowManager中的值?

时间:2017-01-26 作者:Patrick Paul

您好,我在Wordpress环境中使用Javascript文件将TinyMCE编辑器中的按钮与函数集成在一起。我想从select Tag字段中获取值,并将其用于进一步的操作。如何获取所选的值?

init : function(ed, url)
        {
            ed.addButton(\'code-hightlight\',
            {
              title : \'Code-Highlight\',
              cmd : \'code-hightlight-cmd\',
              image : url + \'/prism-icon.jpg\'
            });
            ed.addCommand(\'code-hightlight-cmd\', function()
            {
              tinymce.activeEditor.windowManager.open
              ({
                  title: \'Code-Highlighter\',
                  width : 300,
                  height : 300,
                  html :
                      \'<label>Programmiersprache:<select id="programming-language-id" name="programming-language-name" size="1"><option>ABAP</option><option>C#</option><option>CSS</option><option>HTML</option><option>Java</option><option>Javascript</option><option>PHP</option><option>SQL</option></select></label>\',
                  buttons: [
                      {
                          text: \'Bestätigen\',
                          onclick: function()
                          {
                              var id_id = tinymce.get(\'programming-language-id\');
                              alert(id_id);
                              var id_name = tinymce.get(\'programming-language-name\');
                              alert(id_name);
                              tinymce.activeEditor.execCommand(\'mceInsertContent\', false, "some text");
                              tinymce.activeEditor.windowManager.close();
                          }
                      },
                      {
                          text: \'Schließen\',
                          onclick: \'close\'
                      }
                  ]
              });
            });
        },

enter image description here

1 个回复
SO网友:hcheung

如果我没看错你的问题,这与Javascript编程比WordPress更相关。

要获取HTML select标记的选定选项值或文本,请使用:

var e = document.getElementById("programming-language-id");
var value = e.options[e.selectedIndex].value;  //your code doesn\'t set option value
var text = e.options[e.selectedIndex].text;  //this will get the selected option text