i am checking certain condition in documnet.ready and && operator is not working code snippet lblvalue is empty.
$(function () {
var lblValue = $("#lblRadioText").text();
if (lblValue.length > 0 && hasWhiteSpace(lblValue) > 0) {
$("#rdExportLastTime").css('display', 'inline');
}
});
function hasWhiteSpace(text) {
return text.indexOf(' ') >= 0;
}
can you tell me what is wrong.
i am checking certain condition in documnet.ready and && operator is not working code snippet lblvalue is empty.
$(function () {
var lblValue = $("#lblRadioText").text();
if (lblValue.length > 0 && hasWhiteSpace(lblValue) > 0) {
$("#rdExportLastTime").css('display', 'inline');
}
});
function hasWhiteSpace(text) {
return text.indexOf(' ') >= 0;
}
can you tell me what is wrong.
Share Improve this question asked Nov 25, 2011 at 10:29 ankurankur 4,74315 gold badges67 silver badges104 bronze badges 2-
1
try
if ((lblValue.length > 0) && (hasWhiteSpace(lblValue) > 0)) {
so that both statements are enclosed within their own parentheses. – martincarlin87 Commented Nov 25, 2011 at 10:31 - try this ...if (lblValue.length > 0 && (hasWhiteSpace(lblValue) > 0)) { – balaphp Commented Nov 25, 2011 at 10:32
3 Answers
Reset to default 4You are trying to check if your boolean value is great than 0.
You don't need the 2nd > 0
:
if (lblValue.length > 0 && hasWhiteSpace(lblValue)) {
$("#rdExportLastTime").css('display', 'inline');
}
Actually, that doesn't make any difference to the operation but it's still not needed.
The code seems to work fine to me (slightly adapted for testing): http://jsfiddle/infernalbadger/ZGAj5/1/
You're returning a boolean value out of hasWhiteSpace()
, so you should skip the > 0
in your conditional.
Are you sure that it is operator &&
that fails?
What if you rewrite your code to:
var lblNotZero = lblValue.length > 0;
var hasWhiteSpace = hasWhiteSpace(lblValue) > 0;
if(lblNotZero && hasWhiteSpace)
{
$("#rdExportLastTime").css('display', 'inline');
}
Now set a breakpoint (or output using alert
) to check the values of lblNotZero
and hasWhiteSpace
.
Whenever you suspect language fundamentels such as &&
not working correctly, rethink. Those are extremely well tested.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745132343a4613032.html
评论列表(0条)