JAVASCRIPT问题。 javascript函数不会被触发。 [英] PROBLEM WITH JAVASCRIPT . javascript function are not fired.

查看:91
本文介绍了JAVASCRIPT问题。 javascript函数不会被触发。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <   script    类型  =  text / javascript  >  
function onchange(){
debugger;
var vas = document.getElementById('<% = txt1.ClientID %> ')。值;
alert(vas);
var vas1 = document.getElementById('<% = txt1.ClientID %> ')。值;
if(vas.value ==){
alert('pla enter address');
}

}



< / script>



 <   table     width   =  100%    border   =  0    align   =  center    cellpadding   =  0    cellspacing   =  0 >  
< tr > ;
< td >
name
< / td >
< td >
< asp:TextBox ID = txt1 runat = 服务器 > < / asp: TextBox >
< asp:RequiredFieldValidator runat = server ID = address1Req ControlToValidate = txt1

< span class =code-attribute> 显示 = ErrorMessage < span class =code-keyword> = 请输入广告dress1 .. / >
< / td > ;
< / tr >
< tr >
< td >
name1
< / td >
< td >
< asp:TextBox ID = TextBox1 runat = 服务器 > < / asp: TextBox >
< asp:RequiredFieldValidator runat = server ID = Requ iredFieldValidator1 ControlToValidate = TextBox1

< span class =code-attribute> 显示 = ErrorMessage = 请输入.. / >
< / td >
< / tr >
< tr >
< td >
& nbsp ;
< / td >
< td >
< asp:button id = btnSave tabIndex = 32 runat = server CssClass = OnClientClick = return compare() 文字 = 保存 > < / asp:button >
< asp:Button ID = < span class =code-keyword> btn
文字 = 提交 runat = server OnClientClick = return onchange(); / >
< / td < span class =code-keyword>>
< / tr >
< / table >

解决方案

< blockquote>如果用户lefts字段为空,我似乎试图显示一些警报。你试图通过 RequiredFieldValidator 实现它,但没有得到它的工作。好了,不需要为这个实现javascript函数。只需设置 InitialValue [在这种情况下应为空白]和验证组 [按钮中的任何内容都应相同,并且控制你的控制以及按钮。之后,如果你离开现场的初始值,你的验证器将被调用。



问候.. :笑:


将方法的名称更改为

 <   asp:按钮    id  < span class =code-keyword> =  btn    text   = 提交    runat   =  server    onclientclick   =  return onchange1();    xmlns:asp   = #unknown    /  >  





< script type =   text / javascript> 
function onchange1(){
debugger ;
var vas = document .getElementById(' <%= txt1.ClientID%>')。value;
alert(vas);
var vas1 = document .getElementById(' <%= txt1.ClientID%>')。value;
if (vas.value == ){
alert(' pla enter address');
}

}
< / script>





现在活动开始了


返回compare()方法尚未定义哪个引发JScript错误。

导致错误的原因。


<script type="text/javascript">
        function onchange() {
            debugger;
            var vas = document.getElementById('<%=txt1.ClientID%>').value;
            alert(vas);
            var vas1 = document.getElementById('<%=txt1.ClientID%>').value;
            if (vas.value == "") {
                alert('pla enter address');
            }

        }


</script>

<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
           <tr>
               <td>
                   name
               </td>
               <td>
                   <asp:TextBox ID="txt1" runat="server"></asp:TextBox>
                   <asp:RequiredFieldValidator runat="server" ID="address1Req" ControlToValidate="txt1"

                       Display="None" ErrorMessage="Please enter the Address1.." />
               </td>
           </tr>
           <tr>
               <td>
                   name1
               </td>
               <td>
                   <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                   <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" ControlToValidate="TextBox1"

                       Display="None" ErrorMessage="Please enter the .." />
               </td>
           </tr>
           <tr>
               <td>
                   &nbsp;
               </td>
               <td>
               <asp:button id="btnSave" tabIndex="32" runat="server" CssClass="" OnClientClick = "return compare()" Text="Save"></asp:button>
                   <asp:Button ID="btn" Text="submit" runat="server" OnClientClick="return onchange();" />
               </td>
           </tr>
       </table>

解决方案

I seems like you try to display some alert if user lefts field blank. You tried to implement it through RequiredFieldValidator but didnt get it worked.Well,no need to implement javascript function for this one. Just set InitialValue[should be blank in this case] and validation group [anything but should be same in the button and control both]to your control as well as button.After this,your validator will be invoked if you left the field as it was with initial value.

Regards.. :laugh:


change the name of the method to

<asp:button id="btn" text="submit" runat="server" onclientclick="return onchange1();" xmlns:asp="#unknown" />



<script type="text/javascript">
        function onchange1() {
            debugger;
            var vas = document.getElementById('<%=txt1.ClientID%>').value;
            alert(vas);
            var vas1 = document.getElementById('<%=txt1.ClientID%>').value;
            if (vas.value == "") {
                alert('pla enter address');
            }
 
        }
</script>



Now the event fires


return compare() method not yet define which raise JScript error.
Which cause the error.


这篇关于JAVASCRIPT问题。 javascript函数不会被触发。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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