逻辑“>"以及“<"在Jquery函数内部不起作用

Logical ">" and "<" not working inside Jquery function

本文关键字:quot 函数 内部 不起作用 Jquery 以及 gt 逻辑 lt      更新时间:2023-09-26

我有以下代码:

<script type="text/javascript">
jQuery(function($) {
    var main_content = $('#container'),
     position_top = $('#j_idt7'':idA').position().top,
     position_left = $('#j_idt7'':idA').position().left,
     position_width = $('#j_idt7'':idA').width(),
     position_height = $('#j_idt7'':idA').height(),
     gen_box = null,
     i  = 1;
    console.log( 'Top Image: ' + position_top + 'px');
    console.log( 'Left Image: ' + position_left + 'px');
    console.log( 'Width Image : ' + position_width + 'px');
    console.log( 'Height Image : ' + position_height + 'px');
    main_content.selectable({ 
                start: function(e) {
                        x_begin = e.pageX,
                        y_begin = e.pageY;
                    },
                stop: function(e) {
                        x_end = e.pageX,
                        y_end = e.pageY;
                        if(x_end > position_left +  position_width )
                            return;

                        if( x_end - x_begin >= 1 ) {
                            width  = x_end - x_begin,
                            height = y_end - y_begin;

                        } else {
                            width  = x_begin - x_end,
                            height =  y_end - y_begin;
                            var drag_left = true;
                        }
                        if(width==0 &amp; height==0)
                            {return;}

                        $(this).append('<div class="gen_box_' + i + '">Test</div>');
                        gen_box = $('.gen_box_' + i);
                        $(gen_box).css({
                            'background' : '#006600',
                             'width'     : width,
                             'height'    : height,
                             'position'  : 'absolute',
                             'left'      : x_begin,
                            'text-align' : 'center',
                            'vertical-align': 'middle',
                             'Opacity'      : '0.3',
                             'top'         : y_begin
                        })
                        .draggable({ grid: [1, 1] })
                        .resizable({
          start: function( event, ui ){
                var x = event.clientX;
                var y = event.clientY;
                if(x!=13)
                console.log('Test');
              }
        });
                        drag_left ? $(gen_box).offset({ left: x_end, top: y_begin }) : false;
                        i++;
                }});
});
</script>

一旦我在零件中放入"=="或"!=":

if(x!=13)
console.log('Test');

它工作起来没有任何问题,一旦我用"<"或">"更改它,我在控制台中收到一个错误,说:

未捕获的语法错误:意外的标记;

这真奇怪!!请帮忙吗?

您可以在这里找到转义html代码。

escape html

使用专为编写代码而设计的编辑器。

看起来你正在使用的那个(是哪一个?)不适合写代码:它似乎是HTML编码你的令牌:&正在变成&amp;,等等

<>可能也会发生同样的情况:它们分别被HTML编码为&lt;&gt;,而替换中的分号会导致语法错误。