2010-12-20 24 views
2

私は基本的に別の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:newReply機能で

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); 
} 
+1

replyBox.parentNode.remove(replyBox);

を変更してみてください? –

+0

In reply.addEventListener( "click"、function(){newReplyTxtBox(parent)}、false); newReplyTxtBoxをnewReplyにする必要はありませんか? – HBP

+0

sry私は間違ったものを投稿しました..私はちょうど – twidizle

答えて

1

、あなたがコンソールに表示さん何のエラーreplyBox.parentNode.removeChild(replyBox);

関連する問題