[英]vb.net passing a value of text box in javascript function
MotherTongueTxtBox.Attributes.Add("onblur","val_Length(MotherTongueTxtBox.text,"hi friends",Length);") MotherTongueTxtBox.Attributes.Add(“ onblur”,“ val_Length(MotherTongueTxtBox.text,” hi friends“,Length);”)
in the above statement val_length sa javascript function in tat function the first parameter shd b the contents of the text box ,the second parameter sa string type, is the statement correct i think it s wrong can u suggest a correct valid statement please 在上面的val_length sa javascript函数中,tat函数中的第一个参数shd b文本框的内容,第二个参数sa字符串类型,是正确的语句,我认为这是错误的。
I had a little trouble understanding your question, but I think you're asking that the first parameter be the textbox text, and the second be the length of the textbox text. 我在理解您的问题时遇到了一些麻烦,但是我认为您在问,第一个参数是文本框文本,第二个参数是文本框文本的长度。 This I think should work:
我认为这应该工作:
MotherTongueTxtBox.Attributes.Add("onblur","val_Length(this.value,this.value.length)");
Remember that the above will render the html like: 请记住,上面的代码将使html如下所示:
<input type="text" onblur="val_Length(this.value, this.value.length)" />
In your original statement, the resulting ( incorrect ) html would have been something like: 在您的原始语句中,生成的( 不正确的 )html应该是这样的:
<input type="text" onblur="val_Length(,0)"/>
Since MotherTongueTxtBox.Text
and .Length
would have been string.empty
and 0
respectively (unless it already had initial values...) 由于
MotherTongueTxtBox.Text
和.Length
本来string.empty
和0
分别(除非它已经有了初始值...)
EDIT: 编辑:
Thanks for marking as solution. 感谢您标记为解决方案。 Just as a side note, one thing you may want to consider, is you don't need to pass
this.value.length
in as a parameter, since you're already passing in this.value
. 附带说明一下,您可能要考虑的一件事是,您不需要传递
this.value.length
作为参数,因为您已经传递了this.value
。 You could determine the length within your function. 您可以确定函数中的长度。 Just an idea though like this:
只是一个想法,像这样:
MotherTongueTxtBox.Attributes.Add("onblur","val_Length(this.value, 'Hi')");
And then in your javascript function: 然后在您的javascript函数中:
function val_Length(value, myString) {
var length = value.length;
....
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.