在adavascript中添加控制名称之后:显示错误预期标识符,字符串或数字 [英] After addind the contol name in javascript on : shows error expected identifier, string or number

查看:77
本文介绍了在adavascript中添加控制名称之后:显示错误预期标识符,字符串或数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个texbox:

< asp:TextBox ID =txtnamerunat =server>


我写的必填字段验证脚本:



$(文件).ready(function(){

$(#form1)。validate({

规则:{



& lt;%= txtname.UniqueID%>:{
需要
:真实的

},

},

消息:{



& lt;%= txtname.UniqueID%>:{
需要
:名称是必需的。

},

},

});

});



它在'<%= txtname.UniqueID%>'中显示错误:'预期标识符,字符串或数字。

其实这意味着什么。



我的尝试:



set textbox属性为ClientIDMode =Static而不是<%= txtname.UniqueID%>

仅使用控制ID<%= txtname%>但仍然无效。

I have a texbox:
<asp:TextBox ID="txtname" runat="server">

For required field validation I wrote script as:

$(document).ready(function () {
$("#form1").validate({
rules: {

&lt;%=txtname.UniqueID%>:{
required:true
},
},
messages: {

&lt;%=txtname.UniqueID%>:{
required: "Name is required."
},
},
});
});

Its shows error in line '<%=txtname.UniqueID%>:'expected identifier,string or number.
Actually what it means.

What I have tried:

set textbox property as ClientIDMode="Static" instead of <%=txtname.UniqueID%>
use simply control Id <%=txtname%> but still not work.

推荐答案

(文件).ready(function(){
(document).ready(function () {


(# form1)。验证({

规则:{



& lt;%= txtname.UniqueID%>:{

必填:true

},

},

消息:{



& lt;%= txtname.UniqueID%>:{
需要
:名称是必需的。

},

},

});

});



它在'<%= txtname.UniqueID%>'中显示错误:'预期标识符,字符串或数字。

其实这意味着什么。



我的尝试:



set textbox属性为ClientIDMode =Static而不是<%= txtname.UniqueID%>

仅使用控制ID<%= txtname%>但仍然无效。
("#form1").validate({
rules: {

&lt;%=txtname.UniqueID%>:{
required:true
},
},
messages: {

&lt;%=txtname.UniqueID%>:{
required: "Name is required."
},
},
});
});

Its shows error in line '<%=txtname.UniqueID%>:'expected identifier,string or number.
Actually what it means.

What I have tried:

set textbox property as ClientIDMode="Static" instead of <%=txtname.UniqueID%>
use simply control Id <%=txtname%> but still not work.


请按照以下步骤操作:



Follow these steps:

<asp:TextBox ID="txtname" runat="server">



要获得执行任何客户端验证的ID,请使用:


To get id for performing any client side validation use this:

var obj = document.getElementById('<%=txtname.ClientID%>');



这将解决您的问题,将来会有所帮助


This will solve your problem and will be help full in future


这篇关于在adavascript中添加控制名称之后:显示错误预期标识符,字符串或数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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