【问题标题】:Selecting a div from prototype response Magento从原型响应 Magento 中选择一个 div
【发布时间】:2011-09-19 18:53:30
【问题描述】:

您好,我在 Magento 中使用 Prototype javascript 库。

我收到了 ajax 响应,一切正常。

响应保存在响应变量中。

var response = transport.responseText || "no response text";

我想要的是从响应变量中获取一个 div 及其内容。我完全不知道该怎么做。

我想获取 div 及其内容并将其替换为当前 div 及其内容。

我知道如何通过$('div').update('content') 做到这一点,但我无法获取 div 中内容的确切 div。

【问题讨论】:

    标签: ajax magento html prototypejs


    【解决方案1】:

    你可以试试这样的:

    var container = new Element("div", {}).update(responseText); // this way you get a valid Prototype Element that you can easily query
    // performs your query on the Prototype Element
    // NOTE: remember to not include the root "div" when attaching your response to the html page
    

    希望我回答了你的问题。如果没有,请添加您想要完成的代码示例!

    【讨论】:

    • 感谢您的回答。我有一个变量,其中包含整个 html 页面。变量名称是“响应”。我想通过 $('top-cart').update(ResponseForTopCart); 获取与名为“top-cart”的“div”相关的内容;
    猜你喜欢
    • 2014-07-03
    • 2011-03-06
    • 1970-01-01
    • 2015-07-24
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多