嗨。我是面向对象的 JavaScript 新手,我不知道什么是接口(interface)节点?
下面是我的代码,错误在 第 96 行。
此错误可能是什么原因以及如何解决?
window.onload=initAll;
////////////////////////////////////////////////////////////////////
var msg_dialog=new DialogBox();
var send_msg_but=new Button();
////////////////////////////////////////////////////////////////////
msg_dialog.tit="New Message";
msg_dialog.bod="The Message Body Shall Reside Here";
msg_dialog.fot=send_msg_but;
////////////////////////////////////////////////////////////////////
send_msg_but.label="Send";
send_msg_but.action=msg_dialog.done();
////////////////////////////////////////////////////////////////////
function initAll(){
getDef();
}
function $(x){
return document.getElementById(x);
}
function _(x){
return document.createElement(x);
}
function getDef(){
var xhr;
var url="json/def.json";
if(window.XMLHttpRequest){
xhr=new XMLHttpRequest();
}
else{
xhr=new ActiveXObject("Microsoft:XMLHTTP");
}
xhr.open("GET", url);
xhr.onreadystatechange=function(){
//creating the buffer div here creates 3 instances of the same object because the state changes from 0 (initial) to 1, 2 then 3
if(xhr.readyState==4 && xhr.status==200){
var buffer=$("buffer");
$("body_wrapper").removeChild(buffer);
var data=xhr.responseText;
data=JSON.parse(data);
for(var i in data){
var article=_("div");
article.setAttribute("id", "article");
////////////////////////////////////////////////////////////////////
var img=_("div");
img.setAttribute("id", "img");
var img_data=_("img");
img_data.src=data[i].img;
img.appendChild(img_data);
/////////////////////////////////////////////////////////////////
var caption=_("div");
caption.setAttribute("id", "caption");
//////////////////////////////////////////////////////////////////
var title=_("div");
title.setAttribute("id", "title");
title.innerHTML=data[i].title;
/////////////////////////////////////////////////////////////////
var story=_("div");
story.setAttribute("id", "story");
story.innerHTML=data[i].story;
////////////////////////////////////////////////////////////////
var hlink=_("div");
hlink.setAttribute("id", "hlink");
var a=_("a");
a.href=data[i].href;
a.innerHTML=data[i].htext;
hlink.appendChild(a);
///////////////////////////////////////////////////////////////
caption.appendChild(title);
caption.appendChild(story);
caption.appendChild(hlink);
article.appendChild(img);
article.appendChild(caption);
$("body_wrapper").appendChild(article);
}
}
}
xhr.send(null);
}
function DialogBox(){
this.tit; this.bod; this.fot;
this.render=function(){
var win_width=window.innerWidth;
var win_height=window.innerHeight;
var dialog_box_width=(win_width*0.3); //measurements are in %
///////////////////////////////////////////////////////////////
var dialog_box_overlay=$("dialog_box_overlay");
dialog_box_overlay.style.display="block";
///////////////////////////////////////////////////////////////
var dialog_box=$("dialog_box");
dialog_box.style.left=(0.5*(win_width-dialog_box_width))+"px"; //horizontally centre the div
dialog_box.style.top=(0.1*win_height)+"px";
dialog_box.style.width=dialog_box_width+"px";
dialog_box.style.display="block";
///////////////////////////////////////////////////////////////
$("dialog_box_head").innerHTML=this.tit;
$("dialog_box_body").innerHTML=this.bod;
$("dialog_box_foot").appendChild(this.fot);
}
this.done=function(){
if(typeof $("dialog_box") !="undefined" && $("dialog_box")!=null){
$("dialog_box").style.display="none";
}
if(typeof $("dialog_box_overlay") !="undefined" && $("dialog_box_overlay")!=null){
$("dialog_box_overlay").style.display="none";
}
if(typeof $("dialog_box_foot") !="undefined" && $("dialog_box_foot")!=null){
$("dialog_box_foot").innerHTML="";
}
}
}
function Button(){
var but_bod=_("span"); but_bod.setAttribute("class", "but"); but_bod.addEventListener("click", this.action, false); this.label;
}
最佳答案
问题是
function DialogBox(){
$("dialog_box_head").innerHTML=this.tit;
$("dialog_box_body").innerHTML=this.bod;
$("dialog_box_foot").appendChild(this.fot);
}
var msg_dialog=new DialogBox();
msg_dialog.tit="New Message";
msg_dialog.bod="The Message Body Shall Reside Here";
msg_dialog.fot=send_msg_but;
当您使用 msg_dialog=new DialogBox() 时,
$("dialog_box_foot").appendChild(this.fot) 先运行msg_dialog.fot=send_msg_but 在那之后运行我建议使用
function DialogBox(tit, bod, fot){
$("dialog_box_head").innerHTML = this.tit = tit;
$("dialog_box_body").innerHTML = this.bod = bod;
$("dialog_box_foot").appendChild( this.fot = fot );
}
var msg_dialog=new DialogBox(
"New Message";
"The Message Body Shall Reside Here";
send_msg_but
);
此外,在 Button 中,您忘记返回 HTML 元素,以便使 send_msg_but 成为一个可以附加的节点:
function Button(){
var but_bod=_("span");
but_bod.setAttribute("class", "but");
but_bod.addEventListener("click", this.action, false); // Note `this.action` is undefined
this.label; // This does nothing, so better remove it
return but_bod; // Add this
}
关于javascript - TypeError : Argument 1 of Node. appendChild 没有实现接口(interface)Node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23280317/
我有这个代码File.open(file_name,'r'){|file|file.read}但是Rubocop发出警告:Offenses:Style/SymbolProc:Pass&:readasargumenttoopeninsteadofablock.你是怎么做到的? 最佳答案 我刚刚创建了一个名为“t.txt”的文件,其中包含“Hello,World\n”。我们可以按如下方式阅读。File.open('t.txt','r',&:read)#=>"Hello,World\n"顺便说一下,由于第二个参数的默认值是'r',所以这样
我遇到了一个非常奇怪的问题,我很难解决。在我看来,我有一个与data-remote="true"和data-method="delete"的链接。当我单击该链接时,我可以看到对我的Rails服务器的DELETE请求。返回的JS代码会更改此链接的属性,其中包括href和data-method。再次单击此链接后,我的服务器收到了对新href的请求,但使用的是旧的data-method,即使我已将其从DELETE到POST(它仍然发送一个DELETE请求)。但是,如果我刷新页面,HTML与"new"HTML相同(随返回的JS发生变化),但它实际上发送了正确的请求类型。这就是这个问题令我困惑的
我已经使用Stripe一年多了,基于RyanBates的RailsCast插曲发现here.但是,我的错误处理最近停止工作,而且我以前从未见过此错误。我最近开始在Ruby2.1上运行我的应用程序,据我所知,这就是问题所在。这是我的订阅模型中的一个实例方法:beginsave_with_stripe_paymentrescueStripe::InvalidRequestError=>elogger.error"Stripeerrorwhilecreatingcustomer:#{e.message}"logger.errore.backtrace.join("\n")errors.add
我有这个:AccountSummary我想单击该链接,但在使用link_to时出现错误。我试过:bot.click(page.link_with(:href=>/menu_home/))bot.click(page.link_with(:class=>'top_level_active'))bot.click(page.link_with(:href=>/AccountSummary/))我得到的错误是:NoMethodError:nil:NilClass的未定义方法“[]” 最佳答案 那是一个javascript链接。Mechan
玩转ruby,我已经:#!/usr/bin/ruby-w#WorldweatheronlineAPIurlformat:http://api.worldweatheronline.com/free/v1/weather.ashx?q={location}&format=json&num_of_days=1&date=today&key={api_key}require'net/http'require'json'@api_key='xxx'@location='city'@url="http://api.worldweatheronline.com/free/v1/weather.
我看到有关未找到文件min.map的错误消息:GETjQuery'sjquery-1.10.2.min.mapistriggeringa404(NotFound)截图这是从哪里来的? 最佳答案 如果ChromeDevTools报告.map文件的404(可能是jquery-1.10.2.min.map、jquery.min.map或jquery-2.0.3.min.map,但任何事情都可能发生)首先要知道的是,这仅在使用DevTools时才会请求。您的用户不会遇到此404。现在您可以修复此问题或禁用sourcemap功能。修复:获取文
我有一个用Rails3编写的站点。我的帖子模型有一个名为“内容”的文本列。在帖子面板中,html表单使用tinymce将“content”列设置为textarea字段。在首页,因为使用了tinymce,post.html.erb的代码需要用这样的原始方法来实现。.好的,现在如果我关闭浏览器javascript,这个文本区域可以在没有tinymce的情况下输入,也许用户会输入任何xss,比如alert('xss');.我的前台会显示那个警告框。我尝试sanitize(@post.content)在posts_controller中,但sanitize方法将相互过滤tinymce样式。例如
我有以下代码:classProfileLookup基本上包含大量查找数据,按类别拆分。目的是为数据库中的每个类别创建一个方法。通过Rails控制台,此代码按预期工作:ruby-1.9.3@hub:002>ProfileLookup.available_gendersProfileLookupLoad(0.6ms)SELECT"profile_lookups".*FROM"profile_lookups"WHERE"profile_lookups"."category"='gender'ORDERBYvalue=>["Female","Male"]但是,我的规范不合格。以下规范:requ
出于某种原因,我必须为Firefox禁用javascript(手动,我们按照提到的步骤执行http://support.mozilla.org/en-US/kb/javascript-settings-for-interactive-web-pages#w_enabling-and-disabling-javascript)。使用Ruby的SeleniumWebDriver如何实现这一点? 最佳答案 是的,这是可能的。而是另一种方式。您首先需要查看链接Selenium::WebDriver::Firefox::Profile#[]=
我一直在为使用acts_as_list的模型实现一些不错的交互界面,这些界面可以对我的mRails应用程序中的列表进行排序。我有一个排序函数,在每次拖放之后使用sortable_elementscript.aculo.us函数调用并设置每条记录的位置。这是在拖放完成后处理排序的Controller操作示例:defsortparams[:documents].each_with_indexdo|id,index|Document.update_all(['position=?',index+1],['id=?',id])endend现在我正在尝试对嵌套集模型(acts_as_nested