【问题标题】:phantomjs + jquery: returns empty stringphantomjs + jquery:返回空字符串
【发布时间】:2013-12-19 17:57:52
【问题描述】:

这个网页(test.html):

<p id="test">bla</p>

还有这个js代码:

var page = require('webpage').create();

page.onConsoleMessage = function(msg) {
    console.log("Message: "+msg);
};

page.open("http://localhost/test.html", function(status) {
    if ( status === "success" ) {
        page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
            page.evaluate(function() {
                console.log($("#test").text());
            });
            phantom.exit();
        });
    }
});

结果:

Message:

有人知道为什么我用 phantomjs 运行它时它不显示 p 的文本内容吗?

【问题讨论】:

标签: javascript jquery phantomjs


【解决方案1】:

尝试使用这个:

console.log($("#test").val());

【讨论】:

    猜你喜欢
    • 2012-06-05
    • 2018-02-28
    • 2012-04-20
    • 1970-01-01
    • 2014-03-18
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    相关资源
    最近更新 更多