gpt4 book ai didi

c# - 如何使用动态创建的 jquery 获取文本框的值?

转载 作者:太空宇宙 更新时间:2023-11-03 19:10:41 24 4
gpt4 key购买 nike

我正在从事 mvc4 项目。

如果我动态创建的文本框具有 null 值,我想设置验证警报消息

为此我尝试了以下

  function ValidateForm() {
debugger;
$("#MYFORM tr td").find("input:text").each(function (index) {
debugger;
if ($(this).attr("value") == undefined && $(this).attr("value") == "") {
alert("values are null..")
return false;
}

});
}

Please let me know the syntax for jquery to check the null value.

My problem is I have more than one TEXTBOX's in my FORM

最佳答案

使用val()

    function ValidateForm() {
var flag=0;
debugger;
$("#MYFORM tr td").find("input:text").each(function (index) {
debugger;
if ($(this).val() == undefined && $(this).val() == "" && $(this).val()==null) {//use val() here
alert("values are null..");
flag=1;
//$(this).css("border","1px solid red"); all input which are null will be have red border
}
});
if(flag==1){
return false;
}
else{
return true;
}
}

关于c# - 如何使用动态创建的 jquery 获取文本框的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20904762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com