开发者

a bug related to While and For loops in javascript...!

开发者 https://www.devze.com 2023-01-12 06:24 出处:网络
I have some trouble as simple as debugging a for loop or a while loop. Do you have any clue? a function that returns data withou开发者_如何转开发t any iteration works fine but not the loop.

I have some trouble as simple as debugging a for loop or a while loop. Do you have any clue? a function that returns data withou开发者_如何转开发t any iteration works fine but not the loop.

<script language = "javascript">
        function h(arr)
    {
    <![CDATA[

        var ref = arr[0];

        i = 0
        while(i<arr.length){
            if(arr[i]!= arr[0])
            {
                return 1
            }
            i++;
        }
        return 0

    ]]>
    }

I need it for the XSL not to confuse the < with the tag but consider it as a comparison operator. HELP


Try correcting the following:

The CData tags will want to go outside the function (immediately below and above the open and close script tags respectively). These are only really needed if you are validating your HTML: http://javascript.about.com/library/blxhtml.htm

<script>
<![CDATA[
     // content of your Javascript goes here
]]>
</script>

Add semi-colons on i=0 and return 0 lines.

Use !== instead of != this will do a type comparison as well.

Give us some more info. Its hard to tell


what is <![CDATA[ doing inside your code?

0

精彩评论

暂无评论...
验证码 换一张
取 消