猿问

将 id 值传递给变量不起作用,仅返回其 true

我尝试添加 2 个字段值并将其与下拉值与 JS 进行比较,但它不适用于变量。


    $(document).ready(function() {

           $('#SAVE,#CREATE').mouseover(function(e) {


          var value89 = $('#P315_THRESHOLD').val() || 0;

           var value20 = parseFloat($('#P315_C_RELEASE_REQUEST').val()) || 0;

           var value21 = parseFloat($('#P315_O_RELEASE_REQUEST').val()) || 0;

           var valuetot3 = value20 + value21 ;

           var str = "";

               if( value89 = '>250' &&  valuetot3 < 250  )

                       {

           alert('CAPEX and OPEX request total value should be greater than 250 , current total is' +$('#P315_THRESHOLD').val() || 0);

                       }

        });

     });

预期的结果是它应该对条件发出警报。


跃然一笑
浏览 176回答 2
2回答

动漫人物

if( value89 = '>250' && &nbsp;valuetot3 < 250 &nbsp;)...................................^ 这是做作而不是比较要么使用value89 === '>250'要么value89 >= 250

翻翻过去那场雪

这应该根据您的情况起作用。只需删除= '>250'并替换>=250<script>$(document).ready(function() {&nbsp;&nbsp; &nbsp; $('#SAVE,#CREATE').mouseover(function(e) {&nbsp; &nbsp; &nbsp; &nbsp;var value89 = $('#P315_THRESHOLD').val() || 0;&nbsp; &nbsp; &nbsp; &nbsp;var value20 = parseFloat($('#P315_C_RELEASE_REQUEST').val()) || 0;&nbsp; &nbsp; &nbsp; &nbsp;var value21 = parseFloat($('#P315_O_RELEASE_REQUEST').val()) || 0;&nbsp; &nbsp; &nbsp; &nbsp;var valuetot3 = value20 + value21 ;&nbsp; &nbsp; &nbsp; &nbsp;var str = "";&nbsp; &nbsp; &nbsp; &nbsp;if( value89 >=250 &&&nbsp; valuetot3 < 250&nbsp; ){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert('CAPEX and OPEX request total value should be greater than 250 , current total is' +$('#P315_THRESHOLD').val() || 0);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });});</script>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答