在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);'/>
答案 0 :(得分:5)
JavaScript函数没有类型化参数。尝试你的功能:
function ButtonClick(a, b)
{
if (a == b)
{
alert("Correct!");
}
else
{
alert("Wrong!");
}
}
答案 1 :(得分:0)
function ButtonClick(string a,string b)
javascript不支持数据类型的参数:
尝试:功能ButtonClick(a,b)