Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想打开Datepicker弹出窗口,只通过点击文本和HTML CSS_Css_Html_Datepicker - Fatal编程技术网

我想打开Datepicker弹出窗口,只通过点击文本和HTML CSS

我想打开Datepicker弹出窗口,只通过点击文本和HTML CSS,css,html,datepicker,Css,Html,Datepicker,我正在使用HTML5日期选择器。我想在点击图标或文本后打开这个日期选择器 代码: <label for="YOURID">Through<label> <input id="YOURID" type="date" /> 通过 我尝试使用with label,但不起作用。我只想使用HTML、CSS和javascript(而不是JQUERY) 但它应该与标签一起工作。所以我的首要任务是,我想用html css实现(生成可点击文本和打开日期选择器)。Datepi

我正在使用HTML5日期选择器。我想在点击图标或文本后打开这个日期选择器

代码:

<label for="YOURID">Through<label>
<input id="YOURID" type="date" />
通过
我尝试使用with label,但不起作用。我只想使用HTML、CSS和javascript(而不是JQUERY)


但它应该与标签一起工作。所以我的首要任务是,我想用html css实现(生成可点击文本和打开日期选择器)。Datepicker应在单击文本后打开。

尝试此操作,如果不想显示输入框,只需添加其JS,然后将其宽度设置为10px,使其仅显示日历图标

在HTML中

<input type="text" id="datepicker">

试试这个,如果你不想显示输入框,只需添加他们的JS,然后将其宽度设置为10px,这样只会显示日历图标

在HTML中

<input type="text" id="datepicker">

没有得到你想要的,但我想这就是你想要的

试试这个

  HTML    
  <label for="YOURID">Date Of Birth</label>
  <input type="date" name="dateofbirth" id="YOURID">

  CSS
  [type="date"] {
  background:#fff 
  url(https://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/calendar_2.png)  97% 50% no-repeat ;
  }
  [type="date"]::-webkit-inner-spin-button {
  display: none;
  }
 [type="date"]::-webkit-calendar-picker-indicator {
 opacity: 0;
  }


body {
padding: 4em;
background: #e5e5e5;
font: 13px/1.4 Geneva, 'Lucida Sans', 'Lucida Grande', 'Lucida Sans 
Unicode', Verdana, sans-serif;
    }
label {
display: block;
      }
input {
border: 1px solid #c4c4c4;
border-radius: 5px;
background-color: #fff;
padding: 3px 5px;
box-shadow: inset 0 3px 6px rgba(0,0,0,0.1);
width: 190px;
      }
HTML
出生日期
CSS
[type=“date”]{
背景:#fff
网址(https://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/calendar_2.png)97%50%不重复;
}
[type=“date”]::-webkit内部旋转按钮{
显示:无;
}
[type=“date”]::-webkit日历选取器指示器{
不透明度:0;
}
身体{
填充:4em;
背景:#e5;
字体:13px/1.4日内瓦,“Lucida Sans”、“Lucida Grande”、“Lucida Sans”
Unicode',Verdana,无衬线;
}
标签{
显示:块;
}
输入{
边框:1px实心#C4C4;
边界半径:5px;
背景色:#fff;
填充物:3px 5px;
盒影:插入0 3px 6px rgba(0,0,0,0.1);
宽度:190px;
}

希望这有帮助

没有得到你想要的,但我想这就是你想要的

试试这个

  HTML    
  <label for="YOURID">Date Of Birth</label>
  <input type="date" name="dateofbirth" id="YOURID">

  CSS
  [type="date"] {
  background:#fff 
  url(https://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/calendar_2.png)  97% 50% no-repeat ;
  }
  [type="date"]::-webkit-inner-spin-button {
  display: none;
  }
 [type="date"]::-webkit-calendar-picker-indicator {
 opacity: 0;
  }


body {
padding: 4em;
background: #e5e5e5;
font: 13px/1.4 Geneva, 'Lucida Sans', 'Lucida Grande', 'Lucida Sans 
Unicode', Verdana, sans-serif;
    }
label {
display: block;
      }
input {
border: 1px solid #c4c4c4;
border-radius: 5px;
background-color: #fff;
padding: 3px 5px;
box-shadow: inset 0 3px 6px rgba(0,0,0,0.1);
width: 190px;
      }
HTML
出生日期
CSS
[type=“date”]{
背景:#fff
网址(https://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/calendar_2.png)97%50%不重复;
}
[type=“date”]::-webkit内部旋转按钮{
显示:无;
}
[type=“date”]::-webkit日历选取器指示器{
不透明度:0;
}
身体{
填充:4em;
背景:#e5;
字体:13px/1.4日内瓦,“Lucida Sans”、“Lucida Grande”、“Lucida Sans”
Unicode',Verdana,无衬线;
}
标签{
显示:块;
}
输入{
边框:1px实心#C4C4;
边界半径:5px;
背景色:#fff;
填充物:3px 5px;
盒影:插入0 3px 6px rgba(0,0,0,0.1);
宽度:190px;
}

希望这有帮助

下面的HTML和Javascript日期选择器示例适用于几乎所有浏览器。当浏览器不支持datetime local时,它使用本机html datetime local输入类型,并使用Pikaday(随时间)作为多边形填充。要运行它,您需要从下载Pikaday,解压缩Pikaday.js和Pikaday.css 并将它们放在与包含此代码的文件相同的文件夹中

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="pikaday.css"/>
    <script src="pikaday.js"></script>
    <script type="text/javascript">

function setDate(elementId, date) {
  // "elementId" is the element id of the date field to be updated and will be initialized to "date"
  // in the timezone the user is browsing from.

  if (elementId.type == "datetime-local") {
    // datetime-local is supported, set the initial date in ISO format and show it
    elementId.value = date.getFullYear() + '-'+
    ('0'+(date.getMonth()+1)).slice(-2) + '-' +
    ('0'+date.getDate()).slice(-2) + 'T' +
    ('0'+date.getHours()).slice(-2) + ':' +
    ('0'+date.getMinutes()).slice(-2);
  }
  else {
    // Note that even though we assign the datetime-local input type to time fields it will be read back as text unless
    // datetime-local is actually supported. 
    new Pikaday({
      field          : elementId,
      defaultDate    : date,
      setDefaultDate : true,
      showTime       : true,
      minutesStep    : 5,
      splitTimeView  : false,
      hours24format  : true,
      position       : 'bottom left'
    });
  }
}


function getDateAsString(elementId) {
  var dateAsString;

  if (elementId.type == "datetime-local") {
    dateAsString = elementId.value;
  }
  else {
    var val = elementId.value;
    // Convert time to ISO format which is the same format as that returned by datetime-local

    var month = val.substring(4,7);
    if (month == "Jan") month = "01";
    else if (month == "Feb") month = "02";
    else if (month == "Mar") month = "03";
    else if (month == "Apr") month = "04";
    else if (month == "May") month = "05";
    else if (month == "Jun") month = "06";
    else if (month == "Jul") month = "07";
    else if (month == "Aug") month = "08";
    else if (month == "Sep") month = "09";
    else if (month == "Oct") month = "10";
    else if (month == "Nov") month = "11";
    else if (month == "Dec") month = "12";

    var hour = val.substring(16,18);
    if (val.indexOf("PM") != -1) {
      hour = parseInt(hour);
      if (hour < 12) {
        // Have seen the likes of 21:15 PM returned by pikaday on firefox, hence the hour check
        hour = hour+12;            
      }
    }
    dateAsString = val.substring(11,15) + "-" + month + "-" + val.substring(8,10) + "T" + hour + ":" + val.substring(19,21);    
  }

  return dateAsString;
}


function getDate(elementId) {
   var ds = getDateAsString(elementId);
   var date = new Date(ds.substring(0,4), ds.substring(5,7)-1, ds.substring(8,10), ds.substring(11,13), ds.substring(14,16), ds.substring(17,19));
   return date;
}
    </script>
  </head>

  <body onload="setDate(document.getElementById('demo'), new Date());">
    <input type="datetime-local" id="demo"/>
    <br/><br/>
    <button type="button" onclick="alert(getDateAsString(document.getElementById('demo')))">Show date as string</button>
    <br/><br/>
    <button type="button" onclick="alert(getDate(document.getElementById('demo')))">Show date as date object</button>
  </body>

</html>

函数setDate(elementId,date){
//“elementId”是要更新的日期字段的元素id,将初始化为“日期”
//在用户浏览的时区中。
if(elementId.type==“datetime本地”){
//支持datetime local,以ISO格式设置初始日期并显示
elementId.value=date.getFullYear()+'-'+
('0'+(date.getMonth()+1)).slice(-2)+'-'+
('0'+date.getDate()).slice(-2)+'T'+
('0'+date.getHours()).slice(-2)+':'+
('0'+date.getMinutes()).slice(-2);
}
否则{
//请注意,即使我们将datetime本地输入类型指定给时间字段,它也将作为文本读回,除非
//datetime local实际上是受支持的。
新皮卡日({
字段:elementId,
默认日期:日期,
setDefaultDate:true,
《秀时》:没错,
分钟数:5,
splitTimeView:false,
hours24格式:true,
位置:'左下'
});
}
}
函数getDateAsString(elementId){
变量dateAsString;
if(elementId.type==“datetime本地”){
dateAsString=elementId.value;
}
否则{
var val=elementId.value;
//将时间转换为ISO格式,该格式与datetime local返回的格式相同
var月=val子串(4,7);
如果(月==“一月”)月==“01”;
如果(月==“2月”)月==“02”;
如果(月==“3”)月==“03”;
如果(月==“四月”)月=04;
如果(月==“五月”)月=05;
如果(月==“六月”)月=06;
如果(月==“七月”)月=07;
如果(月==“八月”)月=08;
如果(月==“九月”)月==“09”;
如果(月==“十月”)月=10;
如果(月==“11”)月==“11”;
如果(月==“12”)月=12”;
var小时=val子串(16,18);
如果(val.indexOf(“PM”)!=-1){
小时=parseInt(小时);
如果(小时<12){
//我们已经在firefox上看到了pikaday在晚上21:15返回的类似场景,因此进行了小时检查
小时=小时+12;
}
}
dateAsString=val.substring(11,15)+“-”+月+“-”+val.substring(8,10)+“T”+小时+”:“+val.substring(19,21);
}
返回日期字符串;
}
函数getDate(elementId){
var ds=getDateAsString(elementId);
变量日期=新日期(ds子字符串(0,4)、ds子字符串(5,7)-1、ds子字符串(8,10)、ds子字符串(11,13)、ds子字符串(14,16)、ds子字符串(17,19));
返回日期;
}


将日期显示为字符串

将日期显示为日期对象
下面的HTML和Javascript日期选择器示例适用于几乎所有浏览器。当浏览器不支持datetime local时,它使用本机html datetime local输入类型,并使用Pikaday(随时间)作为多边形填充。要运行它,您需要从下载Pikaday,解压缩Pikaday.js和Pikaday.css 并将它们放在与包含此代码的文件相同的文件夹中

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="pikaday.css"/>
    <script src="pikaday.js"></script>
    <script type="text/javascript">

function setDate(elementId, date) {
  // "elementId" is the element id of the date field to be updated and will be initialized to "date"
  // in the timezone the user is browsing from.

  if (elementId.type == "datetime-local") {
    // datetime-local is supported, set the initial date in ISO format and show it
    elementId.value = date.getFullYear() + '-'+
    ('0'+(date.getMonth()+1)).slice(-2) + '-' +
    ('0'+date.getDate()).slice(-2) + 'T' +
    ('0'+date.getHours()).slice(-2) + ':' +
    ('0'+date.getMinutes()).slice(-2);
  }
  else {
    // Note that even though we assign the datetime-local input type to time fields it will be read back as text unless
    // datetime-local is actually supported. 
    new Pikaday({
      field          : elementId,
      defaultDate    : date,
      setDefaultDate : true,
      showTime       : true,
      minutesStep    : 5,
      splitTimeView  : false,
      hours24format  : true,
      position       : 'bottom left'
    });
  }
}


function getDateAsString(elementId) {
  var dateAsString;

  if (elementId.type == "datetime-local") {
    dateAsString = elementId.value;
  }
  else {
    var val = elementId.value;
    // Convert time to ISO format which is the same format as that returned by datetime-local

    var month = val.substring(4,7);
    if (month == "Jan") month = "01";
    else if (month == "Feb") month = "02";
    else if (month == "Mar") month = "03";
    else if (month == "Apr") month = "04";
    else if (month == "May") month = "05";
    else if (month == "Jun") month = "06";
    else if (month == "Jul") month = "07";
    else if (month == "Aug") month = "08";
    else if (month == "Sep") month = "09";
    else if (month == "Oct") month = "10";
    else if (month == "Nov") month = "11";
    else if (month == "Dec") month = "12";

    var hour = val.substring(16,18);
    if (val.indexOf("PM") != -1) {
      hour = parseInt(hour);
      if (hour < 12) {
        // Have seen the likes of 21:15 PM returned by pikaday on firefox, hence the hour check
        hour = hour+12;            
      }
    }
    dateAsString = val.substring(11,15) + "-" + month + "-" + val.substring(8,10) + "T" + hour + ":" + val.substring(19,21);    
  }

  return dateAsString;
}


function getDate(elementId) {
   var ds = getDateAsString(elementId);
   var date = new Date(ds.substring(0,4), ds.substring(5,7)-1, ds.substring(8,10), ds.substring(11,13), ds.substring(14,16), ds.substring(17,19));
   return date;
}
    </script>
  </head>

  <body onload="setDate(document.getElementById('demo'), new Date());">
    <input type="datetime-local" id="demo"/>
    <br/><br/>
    <button type="button" onclick="alert(getDateAsString(document.getElementById('demo')))">Show date as string</button>
    <br/><br/>
    <button type="button" onclick="alert(getDate(document.getElementById('demo')))">Show date as date object</button>
  </body>

</html>

函数setDate(elementId,date){
//“elementId”是要显示的日期字段的元素id