javascript - Wordpress 中的内联 Javascript

标签 javascript php html wordpress

我有多个表,并且有一个循环遍历它们的选项下拉列表。当我测试 http://codepen.io/fernandob/pen/JEJRMW 中的代码时,一切正常,但将其添加到我的 Wordpress 页面时,它无法运行。在 wordpress 中,我使用的是可视化 Composer ,在文本 block 中,通过文本编辑器,我将 html 代码粘贴到此之后。

            <script>
            if (typeof suffixes !== "undefined") {
                suffixes += ",1390152632";
            } else {
                suffixes = "1390152632";
            }
            function  changeCurrency_1390152632() {
               var idx = document.getElementById("id_selected_currency_1390152632").options.selectedIndex;
               var currency = document.getElementById("id_selected_currency_1390152632").options[document.getElementById("id_selected_currency_1390152632").options.selectedIndex].value;
               var currencies = ["EUR", "USD", "GBP"];
               var i, j;
               for (i = 0; i < 3; i++) {
                  var els = document.getElementsByClassName("currency_" + currencies[i]);
                  var cnt = els.length;
                  if (currency == currencies[i]) {
                     for (j = 0; j < cnt; j++) {
                         els[j].style.display = "block";
                     }

                     var a = suffixes.split(",");
                     for (j = 0; j < a.length; j++) {
                        document.getElementById("id_selected_currency_" + a[j]).options.selectedIndex = idx;
                     }

                  } else {
                     for (j = 0; j < cnt; j++) {
                         els[j].style.display = "none";
                     }
                  }
              }
            }
            </script>

最佳答案

它被替换为 html 代码,因为您使用的是文本 block 。 使用可视化编辑器在结构选项卡下使用 RawHTML 和 RawJS 元素。 HTML 代码粘贴在 Raw HTML 元素中,JavaScrip 代码粘贴在 Raw JS 元素中。

另见图片:

enter image description here

希望这个回答对你有帮助。

关于javascript - Wordpress 中的内联 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41812076/

相关文章:

css - 难以使用 css 和 html 创建内容网格布局

javascript - 如何根据所选列表项一次更改多个图像的 src

javascript - 使用 jquery 中的值设置单选按钮

javascript - Jquery 菜单行为不稳定、定位错误和一般错误

javascript - 获取文本内容pdf.js

php - 无法使用 Spring Boot 从 phpmyadmin SQL 获取数据

php - 嵌套循环和 SQL 查询;需要速度

javascript - 使用 PDFObject 嵌入 Blob

php - 选择多个表mysql

html - IE9 float 额外间距