admin管理员组文章数量:1398832
var id = "<?php echo $val->id; ?>";
var myRadio = $('input[name=<?php echo "mala".$val->id; ?>]').val();
if (myRadio.val.length > 0){
$("#anketa").load('',
{ answer: myRadio, id: id });
}
});
Why this if (myRadio.val.length > 0)
returns it looks like false, when i am sure that there is something in the string. If its not a good way, how to check that the string is empty or not?
var id = "<?php echo $val->id; ?>";
var myRadio = $('input[name=<?php echo "mala".$val->id; ?>]').val();
if (myRadio.val.length > 0){
$("#anketa").load('http://www.svastara.rs/anketa/anketa_m1_data',
{ answer: myRadio, id: id });
}
});
Why this if (myRadio.val.length > 0)
returns it looks like false, when i am sure that there is something in the string. If its not a good way, how to check that the string is empty or not?
-
It shouldn't "look false", it should (probably) throw an error. Why are you trying to take
val
ofval()
? – raina77ow Commented Oct 24, 2012 at 11:10
3 Answers
Reset to default 6No need in val
, since you should already get the value with val()
method in the previous line:
if (myRadio.length > 0) { ... }
if(myRadio)
return true;
else
return false;
You don't need to use myRadio.val.length due to myRadio is already the value of that input. So all you need is to check this variable with length.
var id = "<?php echo $val->id; ?>";
var myRadio = $('input[name=<?php echo "mala".$val->id; ?>]').val();
if (myRadio.length > 0){
$("#anketa").load('http://www.svastara.rs/anketa/anketa_m1_data', { answer: myRadio, id: id });
}
You can have a better explanation at http://www.w3schools./jsref/jsref_length_string.asp
Good luck!
本文标签: javascriptjQuery to check empty stringStack Overflow
版权声明:本文标题:javascript - jQuery to check empty string - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744092744a2589725.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论