【问题标题】:Node.js and node phantom include jqueryNode.js 和 node phantom 包括 jquery
【发布时间】:2015-02-15 23:55:52
【问题描述】:

我目前的代码:

var phantom = require('phantom');
var fs = require('fs');

phantom.create(function(ph) {

  return ph.createPage(function(page) {

    return page.open("http://www.example.com", function(status) {

      page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js', function(err) {

        return page.evaluate(function() {
          return $('#test').value();
        }, function(result) {
          console.log(result)
        });

      });

    });
  });
});

我正在尝试将 jQuery 包含到页面中,所以一切都很好,直到我到达 $() 部分,我得到这个错误:

Undefined 不是构造函数(评估 $('#test').value())

如果不是$('#test').value() 我尝试例如document.title 一切正常。

【问题讨论】:

    标签: javascript jquery node.js phantomjs


    【解决方案1】:

    你确定你复制了正确的错误信息吗:

    TypeError: 'undefined' is not a function (evalating '$('#test').value()')

    无论如何,你的问题是.value(),因为这不是 jQuery 提供的函数。
    您可能正在寻找.val().text()

    【讨论】:

      猜你喜欢
      • 2018-06-13
      • 2021-06-01
      • 2016-09-29
      • 1970-01-01
      • 2016-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-22
      相关资源
      最近更新 更多