【发布时间】:2019-04-22 18:15:12
【问题描述】:
我尝试将我的代码从 jQuery 转换为prototype.js。我执行以下代码,但得到$(...).next is not a function
var editorCounter = 0;
var newEditorIds = [];
$$(".input-text.mceEditor").each(function() {
var next = $(this).next();
var tagName = next.prop("tagName");
if (typeof(tagName) == "undefined") {
var newId = "newEditor_" + editorCounter;
$(this).attr("id", newId);
newEditorIds.push(newId);
editorCounter++;
}
});
newEditorIds.each(function(name, index) {
tinymce.EditorManager.execCommand('mceAddEditor', true, name);
});
它没有完全转换为prototype.js。我仍然需要找出prop() 和attr() 的等价物。
到目前为止,我不明白我做错了什么,因为我在 this site 上告诉自己,它应该可以工作。
原始工作 jQuery 代码:
var editorCounter = 0;
var newEditorIds = [];
jQuery(".input-text.mceEditor").each(function() {
var next = jQuery(this).next();
var tagName = next.prop("tagName");
if (typeof(tagName) == "undefined") {
var newId = "newEditor_" + editorCounter;
jQuery(this).attr("id", newId);
newEditorIds.push(newId);
editorCounter++;
}
});
jQuery.each(newEditorIds, function(i, v) {
tinymce.EditorManager.execCommand('mceAddEditor', true, v);
});
【问题讨论】:
-
你的意思是说原始 jQuery 代码:工作正常但prototype.js 不工作?
-
没错@NegiRox
-
试试 $$(this).next();
-
$$充当querySelectorAll- 接受选择器并给出Array。$充当getElementById- 获取 ID 并提供Element。 -
顺便说一句,
writeAttribute是普通香草setAttribute的更强大版本。没有与prop等效的东西——只需直接在Element对象上使用属性。即,不要说$(element).prop('checked', true),而是说element.checked = true。
标签: javascript jquery prototypejs