1

在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);'/>
4

2 回答 2

5

JavaScript 函数没有类型参数。尝试这样的功能:

function ButtonClick(a, b)
{
  if (a == b) 
  {
     alert("Correct!");
  }
  else
  {
     alert("Wrong!");
  }

}
于 2013-07-25T22:15:44.500 回答
0

函数 ButtonClick(字符串 a,字符串 b)

javascript 不支持具有数据类型的参数:

尝试:函数 ButtonClick(a, b)

于 2013-07-25T22:17:24.630 回答