调用一个JavaScript文件中的另一个JavaScript文件的功能
问题描述:
我想从另一个JavaScript文件(在JavaScript文件中)基本上调用一个函数,但它似乎不工作。调用一个JavaScript文件中的另一个JavaScript文件的功能
在我的main.html中我已经宣布这两个文件,像这样:
<script type="text/javascript" src="Jquery/jquery-1.4.4.js"> </script>
<script type="text/javascript" src="src/Reply.js"> </script>
<script type="text/javascript" src="src/Comment.js"> </script>
和内部Comment.js我调用函数回复()是内Reply.js ..
评论。 JS:
function Comment(message){
var self = this;
var message = message;
//
var comment = document.createElement("li");
comment.id = "comment";
comment.style = "display: none;";
comment.textContent = message;
//empty reply field
var replyField = document.createElement("ul");
replyField.id = "replyField";
//create the appropriate buttons
createButtons(comment);
//append the replyField
comment.appendChild(replyField);
//insert into wall
var parent = document.getElementById("wall");
parent.insertBefore(comment,parent.firstChild);
//effect after insertion
$("ul#wall li:first").fadeOut();
$("ul#wall li:first").fadeIn();
return comment;
}
function newReplyTxtBox(comment){
var buttons = comment.getElementsByTagName("input");
buttons.item(0).disabled="disabled";
var replyBox = document.createElement("div");
replyBox.id="replyBox";
var replyTxt = document.createElement("input");
replyTxt.id="replyTxt";
replyTxt.type="text";
replyTxt.value="Write a reply";
replyTxt.onfocus = function(e){if(this.value==this.defaultValue) this.value='';};
replyTxt.onblur= function(e){if(this.value=='') this.value=this.defaultValue;};
replyBox.appendChild(replyTxt);
createButtons(replyBox);
comment.appendChild(replyBox);
}
function newReply(replyBox){
var message = $("input#replyTxt").val();
var reply = new Reply(message);
replyBox.parentNode.remove(replyBox);
var replyField = replyBox.parentNode.getElementsByTagName("ul").item(0);
replyField.appendChild(reply);
}
的newReply()的简称,一旦你点击“回复按钮”,这是创造像这样:
var submitBtn = button.cloneNode();
submitBtn.value = "submit";
submitBtn.addEventListener("click", function(){newReply(parent)},false);
parent.appendChild(submitBtn);
Reply.js:
function Reply(replyMsg){
var self = this;
var reply = document.createElement("li");
reply.id="reply"
reply.textContent = replyMsg;
var deleteBtn = document.createElement("input");
deleteBtn.value = "delete";
deleteBtn.addEventListener("click", function(){deleteReply(reply)},false);
reply.appendChild(deleteBtn);
return reply;
}
function deleteReply(reply){
reply.parentNode.removeChild(reply);
}
答
在newReply功能,尝试改变replyBox.parentNode.remove(replyBox);
到replyBox.parentNode.removeChild(replyBox);
你在控制台中看到什么样的错误? – 2010-12-20 04:36:06
reply.addEventListener(“click”,function(){newReplyTxtBox(parent)},false); 应该newReplyTxtBox不是简单的newReply? – HBP 2010-12-20 05:02:29
sry我贴了一个错误的..我刚刚更新了它 – twidizle 2010-12-20 05:25:55