2013-09-23 3 views
-1

Я хотел посмотреть, сможет ли кто-нибудь помочь мне с этим. Я хотел посмотреть, как вставить комментарий на мою страницу и обновить его на месте, но проблема в том, что я не уверен, как это сделать. Я попытался выглядеть такими сайтами, как этот, я не знаю, как заставить его работать правильно, так как даже глядя на источник, он действительно не помогает. Это то, что у меня есть до сих пор.Как вставить комментарии на страницу

<!DOCTYPE html> 
<!-- 
this is a comment, the above indicates the formal document type 
(like what a file extension does, but as part of the document) 
--> 
<html> 

<head> 
    <!-- the head section is things that aren't visible on the page, like the title --> 
    <title>Da Blog</title> 

    <!-- we'll put lots more in here later --> 

    <link rel="stylesheet" type="text/css" href="jquery.css" /> 
    <script src="http://code.jquery.com/jquery.js"></script> 
    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"> 
</head> 

<body> 
    <!-- the body is where the visible stuff goes --> 

    <br/><br/><br/> 
    <hr> 
    <h1>My Uber Fake Blog</h1> 
    <hr> 

    <p> 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
This is a wall of text for my uber fake blog!!!! 
</p> 


<div class="panel panel-default"> 
    <div class="panel-heading"> 
     <h3 class="panel-title">Add a comment</h3> 
    </div> 
    <div class="panel-body"> 
     <form id="comment_form"> 
     <div class="form-group"> 
      <input type="textbox" id="comment_name" placeholder="Name" 
      class="input-large form-control"/> 
     </div> 
     <div class="form-group"> 
      <textarea rows="4" cols="60" id="comment" placeholder="Comment" 
      class="form-control"></textarea> 
     </div> 
     <div class="form-group"> 
      <button id="post" class="btn">Post</button> 
     </div> 
     </form> 
    </div> 
</div> 

<div id="comment_list"> 
    <div class="panel panel-default comment"> 
     <div class="panel-heading">etomai</div> 
     <div class="panel-body"> 
      This is my comment. I think the post is too long. 
     </div> 
    </div> 

    <div class="panel panel-default comment"> 
     <div class="panel-heading">etomai</div> 
     <div class="panel-body"> 
      This is my comment. I think the post is too long. 
     </div> 
    </div> 
</div> 

</div> 
</div> 


</body> 

</html> 
+0

Использование JavaScript? Какой смысл делать это? – undefined

+0

Мне тоже интересно для использования. Разумеется, у кого-то, смотрящего на DOM, также будет доступ к консольным сообщениям. Почему бы просто не использовать 'console.log()'? – styfle

+1

Я начал думать, что вам, возможно, не было ясно, что вы имели в виду _comment_; когда речь идет о _JavaScript_, '// this' и'/* this */'является комментарием, а когда речь идет о _HTML/DOM_,' '- комментарий. Тем не менее, я начинаю думать, что вы имели в виду только обычный _HTMLElements_. Прочитайте ссылки MDN для 'document.createElement',' node.appendChild', 'node.insertBefore',' node.cloneNode' и, возможно, 'document.getElementById', чтобы узнать об этом. –

ответ

1

Аналогично добавление HTMLElement к DOM Tree, в комментарий также Узел (NODETYPE8) и будет работать таким же образом. Используйте document.createComment, чтобы создать новый, и вы можете изменить данные , чтобы изменить его содержимое.

+0

Мне нравится идея, но проблема в том, что я не слишком уверен, как ее реализовать. Я бы предположил, что он помещает его и в нижнюю часть страницы. Есть ли все-таки, чтобы заставить его разместить его поверх стека комментариев? –

+0

Комментировать стек? Он помещается туда, куда вы добавляете/вставляете его. –

Смежные вопросы