Javascript 未选择日期选择器时隐藏两个特定div

Javascript 未选择日期选择器时隐藏两个特定div,javascript,jquery,html,Javascript,Jquery,Html,我有下面的html代码,我需要隐藏div-canvas-holder-CT,callratediv-when-date-pickers-range-not-selected 代码 <span style="float: left;margin-left:2em"> <b>Date Range: </b> <input type="text" id="datepicker" > <b>to </b>

我有下面的html代码,我需要隐藏div-canvas-holder-CT,callratediv-when-date-pickers-range-not-selected

代码

<span style="float: left;margin-left:2em"> <b>Date Range: </b>
        <input type="text" id="datepicker" > <b>to </b>
        <input type="text" id="datepicker2"> </span><div id = "Alert" style="float:left;margin-left:2em"> Please select a valid Date Range!</div>
        </br>

    <div id="contain">
    <div id="canvas-holder" style="width:46%;float:left;position: absolute; left: 0px;  top: 100px;">
        <canvas id="chart-area" width="350" height="450"  style="display: block; margin-left:2em">      
    </canvas>
    <center> <b><details>
  <summary>Distribution by Hooks</summary>
</details></center> </b></div>

    <div id="canvas-holder-keymsg" style="width:46%;float:right;position: absolute; right: 0px; top: 100px;">
        <canvas id="chart-area-km" width="350" height="450" style="display: block; margin-left:2em">
    </canvas><center> <b><details>
  <summary>Distribution by Keymessages</summary>
</details></center> </b></div>

<div id="canvas-holder-CT" style="width:46%;float:right;position: absolute; left: 0px; top: 700px;">
        <canvas id="chart-area-CT" width="350" height="450" style="display: block; margin-left:2em">
        </canvas><center> <b><details>
  <summary>Distribution by Call Types</summary>
</details> </b></center></div>

<div id="callratediv" style="float:right; width: 46%;position: absolute; right: 0px; top: 1000px;">
<table id="CallTable" class="dataTable" align="center" style="float:right; width: 80%; height: 100px; ">
    <caption> <b>Call Rate </b></caption>
        <th id="CallNameLabel" style="text-align:center">Number of days in field</th>
        <th id="CallIdLabel" style="text-align:center">Number of calls submitted</th>   
        <th id="CallRateLabel" style="text-align:center">Call Rate </th>        
    </tr>
</table>
</div>
    </div>
不幸的是,该代码适用于divs-canvas holder keymsg、canvas holder,但不适用于上述代码


有人能帮我吗?

使用
$(“#帆布支架CT”)
jQuery的选择器应该是
#画布支架CT
,而不仅仅是ID

使用
$(“#画布支架CT”)
jQuery的选择器应该是
#canvas holder CT
,而不仅仅是ID

您的代码中有很多错误。很难用一种简单的方式将它们全部标记出来,以便于您遵循,但请检查以下几点:

jQuery中的ID选择器需要在ID之前添加
#
。更改以下行:

$("callratediv").hide();
$("canvas-holder-CT").hide();
start = formatDate(startDate);
end = formatDate(endDate);
致:

您的代码中有两行以上内容,因此请修复这两个位置

jQuery中没有
formatDate()
函数。更改这些行:

$("callratediv").hide();
$("canvas-holder-CT").hide();
start = formatDate(startDate);
end = formatDate(endDate);
致:


另外,在前半段代码中没有声明变量
end
以及缺少的
initial()
函数也有一些错误,但您可能在其他代码的某个地方没有发布这些错误。

您的代码中有许多错误。很难用一种简单的方式将它们全部标记出来,以便于您遵循,但请检查以下几点:

jQuery中的ID选择器需要在ID之前添加
#
。更改以下行:

$("callratediv").hide();
$("canvas-holder-CT").hide();
start = formatDate(startDate);
end = formatDate(endDate);
致:

您的代码中有两行以上内容,因此请修复这两个位置

jQuery中没有
formatDate()
函数。更改这些行:

$("callratediv").hide();
$("canvas-holder-CT").hide();
start = formatDate(startDate);
end = formatDate(endDate);
致:


另外,在前半段代码中没有声明变量
end
以及缺少的
initial()
函数也有一些错误,但您可能在其他代码的某个地方没有发布这些错误。

请将行放在这里好吗?我对Jquery不是很在行。contain div已经有了所有这些div,那么为什么我不知道它正在隐藏div-canvas holder keymsg,canvas holder但不是canvas holder CT,callratediv你能把这些行放在这里吗?我不太擅长Jquery.contain div已经有了所有这些div,那么为什么我不知道它隐藏了div-canvas holder keymsg、canvas holder但不是canvas holder CT、callratediv