質問

I am using the jquery function and it is not checking two conditions at once. I want to check for or condition.When I give only one condition in if statement it is working but after giving or it is not working. here is my code

if($("input[title='Nature of the work']").val() != "Execute Business processes" || $("input[title='Nature of the work']").val() != "Deliver periodic reports")
{
$('nobr:contains("Is the work being currently done")').closest('tr').hide();
$('nobr:contains("Frequency of the Deliverables")').closest('tr').hide();
}
else
{
$('nobr:contains("Is the work being currently done")').closest('tr').show();
$('nobr:contains("Frequency of the Deliverables")').closest('tr').show();
}
役に立ちましたか?

解決

please try the below code , i added the full script , try and let me know

<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript&quot;"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            hideShow();
            $("input[title='Nature of the work']").change(function () {
                hideShow();
            });
        });

        function hideShow() {
            var txt = $("input[title='Nature of the work']").val();
            if ((txt != "Execute Business processes") && (txt != "Deliver periodic reports")) {
                $('nobr:contains("IIs the work being currently done")').closest('tr').hide();
                $('nobr:contains("Frequency of the Deliverables")').closest('tr').hide();
            }
            else {
                $('nobr:contains("Is the work being currently done")').closest('tr').show();
                $('nobr:contains("Frequency of the Deliverables")').closest('tr').show();
            }
        }
    </script>

他のヒント

Made some changes to your code, hope it should work.

if(!($("input[title='Nature of the work']").val() == "Execute Business processes" && $("input[title='Nature of the work']").val() == "Deliver periodic reports"))
{
$('nobr:contains("Is the work being currently done")').closest('tr').hide();
$('nobr:contains("Frequency of the Deliverables")').closest('tr').hide();
}
else
{
$('nobr:contains("Is the work being currently done")').closest('tr').show();
$('nobr:contains("Frequency of the Deliverables")').closest('tr').show();
}

Explanation: In your code, if any one of the condition is TRUE the IF statement will be executed as you have used OR operator, but in my code both the conditions will be checked as i have used AND operator.

if(A!=B || C!=D){
//do something
}

For checking both conditions,

if(!(A==B && C==D)){
//do something
}
ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top