我如何结合这些例子?

时间:2010-06-03 21:26:41

标签: javascript

首先,我想再次发布此消息道歉。我是这个论坛的新手。此外,我无法对此问题的第一篇文章发表评论,或向发表评论的用户发送私信,因此我无法与任何试图提供帮助的人进行正确沟通。 与我发表评论或回复此帖的人沟通的正确方法是什么?再次,我很抱歉重复这个问题。顺便说一下,我继续前进。


我刚刚尝试使用Javascript,所以我对它的了解很少。我找到了一个提供留言簿工具(http://www.bfnsoftware.com/index.php?eid=2013)的网站,另一个提供星级工具(addratings.com/)的网站。我想知道要更改的脚本的哪些部分以及要更改它们的内容,以便结果成为每个新留言板帖子下的星级评定工具。顺便说一下,由于我的网站主机上的文件类型限制,我不得不求助于我网站上没有托管的脚本。

留言板代码分为两部分。第一个是输入表格。这是它的基本形式:

<form action = "http://www.bfnsoftware.com/cgi-bin/home/Members/Guestbook/Guestbook.cgi?SiteID=30185&Book=3128" method = "POST">
<input type = "hidden" name = "action" value = "sign">
:: Guestbook ::
Name:
<input type = "text" name = "guestName" size = 30 maxlength = 60>
Email Address:
<input type = "text" name = "guestEmail" size = 30 maxlength = 100>
Website:
<input type = "text" name = "guestWebsite" size = 30 maxlength = 150>
Vote:
<select name = "guestVote" style = "width:203px;">
<option value = "0"> 0 - Worst
<option value = "1"> 1
<option value = "2"> 2
<option value = "3"> 3
<option value = "4"> 4
<option value = "5" SELECTED> 5 - Average
<option value = "6"> 6
<option value = "7"> 7
<option value = "8"> 8
<option value = "9"> 9
<option value = "10"> 10 - Best
</select>
:: Message ::
<textarea cols = 45 rows = 6 name = "guestMessage"></textarea>
<input type = "submit" value = "Submit">
</form>

我没有使用我网站上表单的“guestWebsite”,“guestEmail”或“guestVote”字段。我能够选择让用户在“guestMessage”textarea中输入html。

这是留言簿代码的第二部分。我把它放在我希望帖子解析的页面上。

<script language = "JavaScript" src = "http://www.bfnsoftware.com/cgi-bin/home/Members/Guestbook/Guestbook.cgi?SiteID=30185&Book=3128&action=js">
</script>
<script language = "JavaScript">
 document.write("<font size = 3><b>" + Title + "</b></font><br>");
 document.write("<hr align = left color = #4F4F4F width = 400><p>");
 for (nextE = 0; nextE < FilledEntries; nextE++) {
  document.write('<table border = 0 cellpadding = 1 cellspacing = 0 width = 502 bgcolor = #000000><tr><td width = 502>');
  document.write('<table border = 0 cellpadding = 0 cellspacing = 0 width = 500 bgcolor = #DFDFDF>');
  document.write('<tr><td width = 10></td><td width = 100> Name:</td><td width = 390>' + GuestName[nextE] + '</td></tr>');
  document.write('<tr><td width = 10></td><td width = 100> E-mail: </td><td width = 390>' + GuestEmail[nextE] + '</td></tr>');
  document.write('<tr><td width = 10></td><td width = 100> Website:</td><td width = 390><a href = ' + GuestWebsite[nextE] + '>' + GuestWebsite[nextE] + '</a></td></tr>');
  document.write('<tr><td width = 10></td><td width = 100> Vote:</td><td width = 390>' + GuestVote[nextE] + '</td></tr>');
  document.write('<tr><td width = 10></td><td width = 100> Date:</td><td width = 390>' + GuestDate[nextE] + '</td></tr>');
  document.write('</table></td></tr><tr><td>');
  document.write('<table border = 0 cellpadding = 0 cellspacing = 0 width = 500 bgcolor = #DFDFDF>');
  document.write('<tr><td width = 10></td><td width = 100 valign = top>Message:</td><td width = 390>' + GuestMessage[nextE] + '</td></tr></table>');
  document.write('</td></tr></table><p>');
 }
</script>
<noscript>
<a href = "http://www.bfnsoftware.com/cgi-bin/home/Members/Guestbook/Guestbook.cgi?SiteID=30185&Book=3128&action=view">View Guestbook</a>
</noscript>

我修改过它:

<script language = "JavaScript" src = "http://www.bfnsoftware.com/cgi-bin/home/Members/Guestbook/Guestbook.cgi?SiteID=30185&Book=3128&action=js">
</script>
<script language = "JavaScript">

     document.write("<b>" + Title + "</b><br />");
     for (nextE = 0; nextE < FilledEntries; nextE++) {
         document.write('<div class="entry">Username:   ' + GuestName[nextE] + '<br />');
         document.write('Submission Date:   ' + GuestDate[nextE] + '<br />');
         document.write('Line Submission:   ' + GuestMessage[nextE] + '<br /><br />');
         document.write('</div>');
     }
</script>

接下来是星级评分脚本。这是我正在使用的:

<script type='text/javascript'>
 aR_BgColor="";
 aR_FgColor="";
 aR_url=location.href + "";
 aR_title=document.title + "";
 aR_StarType ='1';
 document.write('<div id="aR_star_info" class="aR_star_info"></div>');
 document.write('<scr'+'ipt type="text/JavaScript" src="http://addratings.com/aR_BootStrap.js"></scr'+'ipt>');
</script>

该网站解释说,如果我想在同一页面上多次使用该代码,我可以,但我必须为 +“” 的一部分定义一个唯一值aR_url = location.href +“”; 如下所示: +“1”代表每个代码,或者每个实例的所有结果都相同。

所以我的问题是“我需要更改脚本的哪些部分以及要将它们更改为什么才能使结果成为每个新留言簿帖子下的星级评定工具?”,在此先感谢您的帮助我可能会得到。

1 个答案:

答案 0 :(得分:2)

您可以将每个新帖子设为星级评级的实例,这样您就可以拥有一个计数器 例如:

post.js

function post()
{
   var rating; 
   this.increase_rating() = function() {..} 
}

在主脚本中,     var newpost = new post();

然后当有人点击按钮增加星标时,它会[onClick=newpost.increase_rating()]

如果您复制src =“http”位置,您可以获取以前无法编辑的留言簿源代码

这是btw,你可以复制并放入你自己的.js文件,并根据需要包含和编辑

var Entries = 3; 
var Title = "book1"; 
var GuestName = new Array(Entries); 
var GuestEmail = new Array(Entries); 
var GuestVote = new Array(Entries); 
var GuestDate = new Array(Entries); 
var GuestWebsite = new Array(Entries); 
var GuestMessage = new Array(Entries); 
var FilledEntries = 0; 

function AddEntry(Name, Date, Email, Vote, Website, Message) 
{
 GuestName[FilledEntries] = unescape(Name); 
 GuestDate[FilledEntries] = unescape(Date); 
 GuestEmail[FilledEntries] = unescape(Email); 
 GuestVote[FilledEntries] = unescape(Vote); 
 GuestWebsite[FilledEntries] = unescape(Website); 
 GuestMessage[FilledEntries] = unescape(Message); 
 FilledEntries++;
} 
AddEntry("RatETest", "6/1/2010 09:29:46 pm", "", "0", "http://", "Rate test 1"); 
AddEntry("Test", "6/1/2010 07:03:07 pm", "", "0", "http://", "Message 2"); 
AddEntry("test1", "6/1/2010 06:21:44 pm", "strangedays@mobilestimulus.com", "5", "http://www.mobilestimulus.com", "Testing the guestbook feature"); 

你可以改变它来在函数本身内添加变量,并且可以使每个帖子成为一个对象。您还可以使用相同的方法添加其他站点的功能(找到其.js的地址或使用页面源)并将其放入此文件中。