无法在按钮单击时调用javascript函数 [英] unable to call a javascript function on a button click

查看:84
本文介绍了无法在按钮单击时调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





i无法在点击按钮上调用javascript函数。

i我收到以下错误



& gt; Microsoft JScript运行时错误:''AddTextBox''未定义





请找到以下代码:



资料来源:

hi ,

i am unable to call a javascript function on a button click .
i am getting the following error

> Microsoft JScript runtime error: ''AddTextBox'' is undefined


Please find the code below:

Source :

<asp:Button ID="Button2"  runat="server"   Text="Add License"
        onClientClick="AddTextBox()" onclick="Button2_Click1" />

       <div id="TextBoxContainer">
       <!----Textboxes will be added here--->
    </div>
    <script type="text/javascript">

        function GetDynamicTextBox(value) {

            return '<input name = "DynamicTextBox" type="text" value="' + value + '"/>' + '<input type="button" value="Remove" onclick="RemoveTextBox(this)"/>'
        }
         function AddTextBox(){
               var div = document.createElement('DIV');
               div.innerHTML = GetDynamicTextBox("");
               document.getElementById("TextBoxContainer").appendChild(div);
               }
        function RemoveTextBox(div) {
            document.getElementById("TextBoxContainer").removeChild(div.parentNode);
        }
        function RecreateDynamicTextBox(){
            var values=eval('=Values');
            if(values!=null){
              var html="";
              for(var i=0;i<values.length;i++){>
                 html+="<div>" + GetDynamicTextBox*(values[i] + "<div>";
                 }
                 document.getElementById("TextBoxContainer").innerHTML=html;
                 }
             }
             window.onload=RecreateDynamicTextBoxes;

    </script>





按钮代码点击:



Code of button click:

protected void Button2_Click(object sender, EventArgs e)
{
    string[] textboxvalues = Request.Form.GetValues("DynamicTextBox");
    JavaScriptSerializer serializer = new JavaScriptSerializer();
    this.Values = serializer.Serialize(textboxvalues);
}



请提前帮助和谢谢....



谢谢


Please help and thanks in advance....

Thanks

推荐答案

这是一个语法错误。因为你在这里错过了一个紧密的大括号''''':

It''s a syntacticle error. Since you missed a close braces '')'' here:
html+="<div>" + GetDynamicTextBox*(values[i] + "<div>";



用以下内容替换该行:


Replace the line with following:

html+="<div>" + GetDynamicTextBox*(values[i] + "<div>");



还有onload你打电话 window.onload = RecreateDynamicTextBoxes; 而你的函数名是 RecreateDynamicTextBox



--Amit


And also onload you are calling window.onload=RecreateDynamicTextBoxes; whereas your function name is RecreateDynamicTextBox

--Amit


我认为,在onClick事件中你调用了
I think, in onClick event you have called
onclick="Button2_Click1"



但是没有相同的定义。



所以通过将onClick事件更改为


but there is no definition for the same.

So by changing the onClick event to

onclick="Button2_Click"

可能适合你。


这篇关于无法在按钮单击时调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆