2010-12-20 2 views
1

javascriptの中に完全に機能する2つの関数を定義しましたが、プロトタイプの中に入れても機能しないようです。javacriptでプロトタイプを使用する

wall.html:。

<script type="text/javascript" src="Jquery/jquery-1.4.4.js"> </script> 
<script type="text/javascript" src="src/CommentManager.js"> </script> 
<script type="text/javascript" src="src/Reply.js"> </script> 
<script type="text/javascript" src="src/Comment.js"> </script> 
<script type="text/javascript"> 
    $(document).ready(function(){ 
     CommentManager(); 
     $("form#newMessage").submit(function(){ 
      var message = $("input#newMessageTxt").val(); 
      var newComment = new Comment(message); 
     }); 
    }); 
</script> 
</head> 

<body> 
    <div class="message"> 
     <form id="newMessage"&gt;> 
      <input type="text" id="newMessageTxt" height="200px" value="Write a message" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" /> 
      <input type="submit" value="Submit" ></button> 
     </form> 
    </div> 
</body> 

が、私はGoogleChromeをでデバッグツールを実行したときに変な部分が$( "#フォームのnewMessage")であり、提出は全く呼び出しません。

function Comment(message){ 
    var self = this; 
    var message = message; 

    var comment = document.createElement("li"); 
    comment.id = "comment"; 
    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 
    addComment(comment); 
    //effect after insertion 
    Effect(comment); 
    $(comment).mouseleave(function() {mouseOut(comment);}); 
    $(comment).mouseenter(function() {mouseOver(comment);}); 
    return comment; 
} 
Comment.prototype={ 
    deleteComment : function (comment){ 
     $(comment).fadeOut(); 
     setTimeout(function() {comment.parentNode.removeChild(comment);},500); 
    }, 
//there are more methods here 
} 

Commentmanager.js:createButtonsを定義している

function CommentManager(){ 
    var owner = null; 

    var wall = document.createElement("ul"); 
    wall.id = "wall"; 

    document.body.appendChild(wall); 
    return wall; 
} 

function addComment(comment){ 
    var wall = document.getElementById("wall"); 
    wall.appendChild(comment); 
} 
+0

悲しいことに、jqueryを話せないので、私ができることはすべてretagだった。 'プロトタイプ'はやや誤解を招いていた。 –

+0

デバッグを試しましたか? – SLaks

+0

実際、「プロトタイプ」は、ソフトウェア開発の他の場所とは異なる意味を持つjavascript内の記述的な用語です(残念なことに:()。「prototype」の説明についてはhttp://javascript.crockford.com/prototypal.htmlを参照してください) 'はjsで、おそらく 'javascript-prototype'はタグでなければなりませんか? –

答えて

0

ので(メッセージを)コメント(私はプロトタイプの機能を設定しているところである)

Comment.jsを作成されることはありません? (Comment.js内)?

また、最後のファイルはCommentmanager.jsと題名しましたが、wall.htmlにはCommentManager.js(wall.jsに大文字のMが書かれています)があります。私は、それはここでのタイプミスだと思っているのですが、サーバー上のファイル名がhtmlスクリプトタグと一致していることを確認してください。

関連する問題