我試圖製作允許表情的留言本。我已經使它解析了像[smile]
等東西,並用圖像替換它,但我不能得到一件事情工作。我的留言板存在問題
當用戶點擊笑臉時,我希望它在文本框中插入正確的標籤,但它什麼都不做。我習慣於JavaScript來嘗試插入標籤。
見鏈接:
http://www.vittoriosastarsnursery.com/guestsign.aspx
下面是代碼:
<%@ Page Explicit="True" Language="VB" Debug="True" ValidateRequest="false" %>
<%@ Register TagPrefix="aspHut" TagName="templateTop" Src="guesttop.ascx" %>
<%@ Register TagPrefix="aspHut" TagName="templateBottom" Src="guestbottom.ascx" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
Dim strConnection As String = "provider=Microsoft.Jet.OLEDB.4.0;data source=" + Server.MapPath("guestbook.mdb.resources")
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
If (Page.IsValid) Then
' using .Replace("'", "") to remove naughty single quote
Dim sName As String = Server.HtmlEncode(txtName.Text.Replace("'", ""))
Dim sEmail As String = Server.HtmlEncode(txtEmail.Text.Replace("'", ""))
Dim sMessage As String = Server.HtmlEncode(txtMessage.Text.Replace("'", ""))
Dim objConnection As OleDbConnection
Dim objCmd As OleDbCommand
Dim strSQL As String = "INSERT INTO messages (name, email, message) VALUES ('" & sName & "', '" & sEmail & "', '" & sMessage & "')"
objConnection = New OleDbConnection(strConnection)
objConnection.Open()
objCmd = New OleDbCommand(strSQL, objConnection)
objCmd.ExecuteNonQuery()
objConnection.Close()
Response.Redirect("Guestbook.aspx")
Else
Exit Sub
End If
End Sub
</script>
<aspHut:templateTop ID="UserControl1" runat="server"></aspHut:templateTop>
<script language="JavaScript">
var bodytext = "";
function AddText(NewCode) {
var dob = document.formSign.txtMessage
if (dob.createTextRange && dob.caretPos) {
var caretPos = dob.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
}
else if (dob.setSelectionRange) {
dob.value = dob.value.substring(0, dob.selectionStart) + NewCode + dob.value.substring(dob.selectionEnd, dob.value.length);
}
else {
dob.value += NewCode;
}
dob.focus();
bodytext = "";
}
</script>
<form id="formSign" runat="server">
<p>
Please enter the following requested information below to sign the guestbook.
<table>
<tr>
<td align="left">
<b>Your Name:</b><asp:requiredfieldvalidator id="nameReqVal" runat="server" controltovalidate="txtName"
errormessage="Your Name.">*</asp:requiredfieldvalidator>
</td>
<td align="right">
<asp:textbox id="txtName" runat="server"></asp:textbox>
</td>
</tr>
<tr>
<td align="left">
<b>Your Email Address:</b><asp:regularexpressionvalidator id="emailRegEx" runat="server"
controltovalidate="txtEmail" errormessage="Your Email." validationexpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:regularexpressionvalidator>
</td>
<td align="right">
<asp:textbox id="txtEmail" runat="server"></asp:textbox>
</td>
</tr>
<tr align="left">
<td colspan="3">
<b>Your Message:</b><asp:requiredfieldvalidator id="messageReqVal" runat="server"
controltovalidate="txtMessage" errormessage="Your Message.">*</asp:requiredfieldvalidator>
</td>
</tr>
<tr align="left">
<td colspan="2">
<asp:textbox id="txtMessage" runat="server" textmode="MultiLine" columns="50" rows="10"></asp:textbox>
</td>
<td>
<table>
<tr>
<td>
<a href="javascript:void(AddText('[angel]'))">
<img src="/Images/Smileys/angel_smile.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[angry]'))">
<img src="/Images/Smileys/angry.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[teeth]'))">
<img src="/Images/Smileys/baring_teeth.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[confused]'))">
<img src="/Images/Smileys/confused.gif" border="0" height="22" width="22" /></a>
</td>
</tr>
<tr>
<td>
<a href="javascript:void(AddText('[cry]'))">
<img src="/Images/Smileys/cry.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[dunno]'))">
<img src="/Images/Smileys/dont_know.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[ssh]'))">
<img src="/Images/Smileys/dont_tell.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[haha]'))">
<img src="/Images/Smileys/hahaha.gif" border="0" height="22" width="22" /></a>
</td>
</tr>
<tr>
<td>
<a href="javascript:void(AddText('[nerd]'))">
<img src="/Images/Smileys/nerd.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[omg]'))">
<img src="/Images/Smileys/omg.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[party]'))">
<img src="/Images/Smileys/party.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[red]'))">
<img src="/Images/Smileys/red.gif" border="0" height="22" width="22" /></a>
</td>
</tr>
<tr>
<td>
<a href="javascript:void(AddText('[smile]'))">
<img src="/Images/Smileys/regular_smile.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[rolleyes]'))">
<img src="/Images/Smileys/roll.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[sad]'))">
<img src="/Images/Smileys/sad_smile.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[wink]'))">
<img src="/Images/Smileys/wink_smile.gif" border="0" height="22" width="22" /></a>
</td>
</tr>
<tr>
<td>
<a href="javascript:void(AddText('[sarcastic]'))">
<img src="/Images/Smileys/sarcastic.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[shades]'))">
<img src="/Images/Smileys/shades.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[what]'))">
<img src="/Images/Smileys/what_smile.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[sick]'))">
<img src="/Images/Smileys/sick.gif" border="0" height="22" width="22" /></a>
</td>
</tr>
<tr>
<td>
<a href="javascript:void(AddText('[sleepy]'))">
<img src="/Images/Smileys/sleepy.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[grin]'))">
<img src="/Images/Smileys/teeth_smile.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[thinking]'))">
<img src="/Images/Smileys/thinking.gif" border="0" height="22" width="22" /></a>
</td>
<td>
<a href="javascript:void(AddText('[tongue]'))">
<img src="/Images/Smileys/tongue_smile.gif" border="0" height="22" width="22" /></a>
</td>
</tr>
</table>
</td>
</tr>
<tr align="left">
<td colspan="3">
<asp:validationsummary id="ValSum" runat="server" width="312px" headertext="Please correct the following error(s):"></asp:validationsummary>
<asp:button id="btnSubmit" onclick="btnSubmit_Click" runat="server" text="Sign!"></asp:button>
</td>
</tr>
</table>
</form>
<p align="center">
<a href="guestbook.aspx">View the guestbook</a></p>
<aspHut:templateBottom ID="UserControl2" runat="server"></aspHut:templateBottom>
您可以發佈代碼,而不是一個鏈接?錯誤日誌中是否有錯誤可見? – TJHeuvel
似乎它得到「textarea」失敗。我確信足夠的點擊並加載「笑臉」數據。 –
我們需要在您的問題中發佈相關代碼,否則您的問題將很快關閉。 –