首页 > 解决方案 > 如何在wordpress中编写jquery

问题描述

我正在尝试在wordpress divi 代码模块中使用 jQuery 获取 div 的值并在 url 中传递值

我在控制台内收到未定义的错误

这是我的jQuery代码

jQuery(".xsub").click(function(){

console.log(jQuery("div#user-region").val());
var xst = document.getElementById('user-region');
console.log(xst.value);
window.location.href ='https://jobplace360.com/hud/hud-listings/?'+xst;
});

新页面打开时,我进入了 url [object%20HTMLDivElement]

标签: jquerywordpress

解决方案


试试这个代码:

  var $=jQuery.noConflict();

  $(document).ready(function(){
      // Handler for .ready() called.
      $(".xsub").click(function(){
        console.log($("div#user-region").val());
        var xst = $('#user-region').html();
        console.log(xst);
        window.location.href ='https://jobplace360.com/hud/hud-listings/?'+xst;
      });

    });

推荐阅读