比较javascript中的两个字符串;ASP.NET c#
本文关键字:字符串 两个 ASP NET javascript 比较 | 更新日期: 2023-09-27 18:24:54
在asp页面上,我创建了这个函数来检查两个字符串是否相等:
<script type="text/javascript">
function ButtonClick(a, b)
{
if (a == b)
{
alert("Correct!");
}
else
{
alert("Wrong!");
}
}
</script>
然后,我创建了这个功能,当页面加载时,我会使用它来显示所有内容:
public void FillPageSpelling()
{
ArrayList videoList1 = new ArrayList();
if (!IsPostBack)
{
videoList1 = ConnectionClass.GetSpelling(1);
}
else
{
int i = Convert.ToInt32(DropDownList1.SelectedValue);
videoList1 = ConnectionClass.GetSpelling(i);
}
StringBuilder sb = new StringBuilder();
foreach (Spelling sp in videoList1)
{
sb.Append(
string.Format(
@"<table class='VideoTable'>
<tr>
<td align='center'><font face='Verdana'> <font size='3'>Level:</font> <font size='2'>{3}</font></font></td>
</tr>
<tr>
<td align='center'><font face='Verdana'> <font size='3'>Sentence:</font> <font size='2'>{1}</font></font></td>
</tr>
<tr>
<td align='center'><font size='3'>Sound:<audio controls><source src=sound/{2}></audio>
<font face='Verdana'> <font size='2'> </font> </font></td>
</tr>
<tr>
<tr><td align='center'><font face='Verdana'> <font size='3'>Write the word here: <input type=text name=TextBox1></font></font> </td> </tr>
<td><button name=btnCheck type=button onclick='ButtonClick(TextBox1.Text, lblWord.Text)'>Check</button> </td>
<td><button name=btnCheat type=button onclick='ButtonClick(TextBox1.Text, lblWord.Text)'>Cheat</button> </td>
</tr>
<tr>
<td align='center'><font face='Verdana'> <font size='3'>Word:</font> <font size='2'><asp:Label ID=lblWord runat=server>{4}</asp:Label></font></font></td>
</tr>
</br>
</table>", sp.SID, sp.Sentence, sp.Sound, sp.Level, sp.Word));
lblOutput.Text = sb.ToString();
}
事实证明,我在这里犯了一个错误:<td><button name=btnCheck type=button onclick='ButtonClick(TextBox1.Text, lblWord.Text)'>Check</button> </td>
我将标签lblWord改为文本框-TextBox2,这就是您应该如何调用函数:
<input type=button value='Check' class='p-userButton' onClick='ButtonClick(document.getElementById(""TextBox1"").value, document.getElementById(""TextBox2"").value);'/>
JavaScript函数没有类型化参数。试试你的功能:
function ButtonClick(a, b)
{
if (a == b)
{
alert("Correct!");
}
else
{
alert("Wrong!");
}
}
功能按钮点击(字符串a,字符串b)
javascript不支持数据类型为的参数
try:function按钮点击(a,b)