0

我试图能够通过内联编辑从 ExpressionEngine 通道编辑数据。我遵循了这个提示: http ://www.3roadsmedia.com/blog/inline-editing-with-expressionengine-and-ajax/

我可以在空白页上工作。但是当 jquery 涉及时。我收到此错误:

Uncaught TypeError: Object [object Object] has no method 'attachEvent' 

我用谷歌搜索了一下,我相信它与$选择器混淆了。因为当我添加这个时:

var $ = jQuery.noConflict();

它开始工作了。但我还有另一个错误,

 Uncaught TypeError:Object [object Object] has no method 'dispatchEvent' 

哪个可能与选择器错误有关?看起来有一些使用原型和 jquery 的已知问题。

这是另一个使用原型的脚本:

Event.observe(window, 'load', init, false);


function init() {
    makeEditable("editTitle");
}

function makeEditable(id) {
    Event.observe(id, 'click', function(){edit($(id))}, false);
    Event.observe(id, 'mouseover', function(){showAsEditable($(id))}, false);
    Event.observe(id, 'mouseout', function(){showAsEditable($(id), true)}, false);
}


function showAsEditable(obj, clear) {
    if (!clear) {
        Element.addClassName(obj, 'editable');
    } else {
        Element.removeClassName(obj, 'editable');
    }
}


function edit(obj) {
    Element.hide(obj);

    var textbox ='<div class="edit-area" id="' + obj.id + '_editor"><textarea name="' + obj.id + '" id="' + obj.id + '_edit">' + obj.innerHTML + '</textarea>';

    var button = '<input type="button" value="SAVE" id="' + obj.id + '_save"/> OR <input type="button" value="CANCEL" id="' + obj.id + '_cancel"/></div>';

    new Insertion.After(obj, textbox+button);

    Event.observe(obj.id+'_save', 'click', function(){saveChanges(obj)}, false);
    Event.observe(obj.id+'_cancel', 'click', function(){cleanUp(obj)}, false);
}


function cleanUp(obj, keepEditable) {
    Element.remove(obj.id+'_editor');
    Element.show(obj);
    if (!keepEditable) showAsEditable(obj, true);
}


function saveChanges(obj) {
    var new_content = escape($F(obj.id+'_edit'));

    obj.innerHTML = "Saving…";
    cleanUp(obj, true);

    var success = function(t){editComplete(t, obj);}
    var failure = function(t){editFailed(t, obj);}

    var url = 'http://path-to-your-scripts-folder/edit.php';
    var pars = 'id=' + obj.id + '&content=' + new_content;
    var myAjax = new Ajax.Request(url, {method:'post',
    postBody:pars, onSuccess:success, onFailure:failure});
}


function editComplete(t, obj) {
    obj.innerHTML = t.responseText;
    showAsEditable(obj, true);
}


function editFailed(t, obj) {
    obj.innerHTML = 'Sorry, the update failed.';
    cleanUp(obj);
}
4

1 回答 1

1

由于我只将 Prototype 用于特定的 Ajax 任务,因此我将$选择器替换为,在和$p中使用简单的查找和替换。prototype.jseditinplace.js

于 2013-01-31T07:53:12.817 回答