如何在带有if-else语句的javascript中使用表Id调用表

如何在带有if-else语句的javascript中使用表Id调用表,javascript,html,jsp,spring-mvc,Javascript,Html,Jsp,Spring Mvc,我试图用一个值“图形”显示一个表。若图形值为0,则应显示表1(表id),若图形值为10,则应显示表2(表id)。我试图用带有if-else的java脚本来说明这一点。我不知道如何在if-else语句中调用java脚本中的表 <script> $(document).ready( function () { myFunc(); }); function myFunc(){ console.log

我试图用一个值“图形”显示一个表。若图形值为0,则应显示表1(表id),若图形值为10,则应显示表2(表id)。我试图用带有if-else的java脚本来说明这一点。我不知道如何在if-else语句中调用java脚本中的表

               <script>
    $(document).ready( function () {

        myFunc();

    });
    function myFunc(){

        console.log("input value", document.getElementById("graph").value)  
        if (document.getElementById('graph').value==00){


        }


    }</script>

$(文档).ready(函数(){
myFunc();
});
函数myFunc(){
console.log(“输入值”,document.getElementById(“图形”).value)
if(document.getElementById('graph')。值==00){
}
}

如何在if-else语句中写入调用表假设调用函数时文档中的两个表都可用,它应该如下所示

<script>
    $(document).ready( function () {
    myFunc();
});

function myFunc(){
    console.log("input value", document.getElementById("graph").value);
    var val = document.getElementById("graph").value;
    document.getElementById('table1').style.display = val== 0 ? '' : 'none';
    document.getElementById('table2').style.display = val== 10 ? '' : 'none';
}</script>

如果可能的话,希望这对你有所帮助。希望有帮助

$(document).ready(function(){
   if($('#graph').val()=='00'){
        $('#table1').show();
        $('#table2').hide();
     }else if($('#graph').val()=='10'){
            $('#table2').show();
            $('#table1').hide();
             }
});

试试这个…它已经过测试了

    jQuery(document).ready( function () {
       myFunc();
    });
   function myFunc()
   {

            console.log("input value", document.getElementById("test").value);  
             if (document.getElementById('test').value=="testing"){

                alert("got in if");
             }

            else 
           {
            //this will hit the column of a table now change it according to your requirements
           //you may write $ instead of jQuery,I assigned a value to a column you set it as you need...
          jQuery("#your_target_id_in_table").val("hello"); 
          alert(jQuery("#your_target_id_in_table").val()); //you may write $ instead of jQuery
          }


  }

在控制台输入值0 listPayout.htm(第1196行)中,2 TypeError:document.getElementById(…)为空document.getElementById('tableId1')。style.display='none';你有打字错误。。。替换document.getElementById('tableId1')。style.display='none';使用document.getElementById('table1').style.display='none';(删除字符串“tableId1”中的Id)我可以在正文中调用此onload。。。或者我可以在脚本中保存和使用是的。。。但是第一个人先回答。。。所以我给他做了记号…很抱歉没给你做记号你的工作做得很好。。。非常感谢你,耶。。。shukriya:D:D aapka swagat hai;)
    jQuery(document).ready( function () {
       myFunc();
    });
   function myFunc()
   {

            console.log("input value", document.getElementById("test").value);  
             if (document.getElementById('test').value=="testing"){

                alert("got in if");
             }

            else 
           {
            //this will hit the column of a table now change it according to your requirements
           //you may write $ instead of jQuery,I assigned a value to a column you set it as you need...
          jQuery("#your_target_id_in_table").val("hello"); 
          alert(jQuery("#your_target_id_in_table").val()); //you may write $ instead of jQuery
          }


  }