date.getElementById的日期时间不起作用

编程入门 行业动态 更新时间:2024-10-26 17:22:17
本文介绍了date.getElementById的日期时间不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 下面你看到一个Zendesk的自定义代码。一切正常,直到我想实现日期/时间片段。

通常脚本的工作原理如下:

1 - 有一个按钮,说打印票。

2 - 该按钮有一个onclick事件打开打印机友好页面准备打印。

在实现日期/时间代码(我没有做好以后我相信),我只得到可打印的版本的票,但是时间不显示。 (没有发现真的)

发生的唯一的事情是,没有剩余的可打印形式显示日期和时间。

我认为javascript的placemanet不在正确的地方,它需要在头部,也是由javascript生成的。 b $ b

可以有人请帮我这个吗?或者把我指向一个例子,该怎么办?

< style> input.createtable { display:none; } < / style> < script language =JavaScript> //获取今天的当前日期。 var now = new Date(); //数组列表天数。 var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); //数组列表。 var months = new Array('January','February','March','April','May','June','July','August','September',' '十一月十二月'); //计算一周当前日数。 var date =((now.getDate()< 10)?0:)+ now.getDate(); //计算四位数年份。 函数fourdigits(number){ return(number< 1000)?数字+ 1900:数字} //一起加入 today = days [now.getDay()] +,+ months [now.getMonth()] ++ date +,+ (fourdigits(now.getYear())); //打印出数据。 // document.write(今天); //开始更改代码 document.getElementById(date)innerHTML = today; //结束修改后的代码 // End - > < / script> < script language =JavaScript> <! - writeConsole = function(content){ top.consoleRef = window.open('','myconsole','width = 800,height = 800' +',menubar = 0' +',toolbar = 0' +',status = 0' +',scrollbars = 1' +',resizable = 1') // top.consoleRef.document.open(text / html,replace); top.consoleRef.document.writeln('< html>< head>< title>签名页面< / title>< / head>' +'&&style = ; {{color:#FFFFFF; border-bottom:1px solid#000000; background-color:#CCCCCC;} tr {color:#000000; border-bottom:1px solid #cccccc;} td.small {color:#000000 ; font-size:12px; font-family:Verdana,Arial,Helvetica,sans-serif;} td.large {color:#000000; font-size:120%; font-family:Arial,Helvetica,sans-serif; font-weight:bold; text-align:center;}< / style>' +'< link href =asset3.zendesk/stylesheets_old/zd_print.css?1270161524 =print =stylesheettype =text / css/>' +'< body onLoad =self.focus()style =background:white; font-size:11px ; font-family:Verdana,Arial,Helvetica,sans-serif>' +'< center>< A HREF =javascript:window.print()>打印Werkorder< / A> < / center>' +'< table width =100%>< tr>< td align =leftvalign =midd ' +'< / td>< br />' +'www.domain.nl< br />' +'电话:058- 111111111< br />' +'E-mail info@domain.nl' +'< / tr>< / table>' + content + '< / body>< / html>') top.consoleRef.document.close()} // - > < / script> < form> < input class =createtablename = userInput type = textarea size =1value =< table width = 100%height = 825 border = 0 cellpadding = 6 cellspacing = 4> < tr> < th colspan = 6>< h1> WERKORDER NR#:{{ticket.id}}< / h1>< / th> < / tr> < tr> < td colspan = 6< hr width = 100%noshade = noshade />< / td> < / tr> < ; tr> < td width = 13%valign = top>< strong> Klantinformatie:< / strong>< / td> < td width = 87%align = left valign =顶部>< p>< strong>基准:< div id = date>< / div> < br /> Naam< / strong> ;: { ticket.requester.name}}< br /> < strong> Bedrijf:< / strong> {{ticketanization.name}}< br /> < strong& ; Telefoonnummer:< / strong> {{ticket.ticket_field_484140}}< br /> < strong>电子邮件:< / strong> {{ticket.requester.email}}< p> ;< / td> < / tr> < tr> < td valign = top>< strong>在ontvangst genomen中:< / strong>< / td> < td align = left valign = top>< strong> Merk& amp; amp;型号:< / strong> {{ticket.ticket_field_483591}}< br /> < strong>硬件类型:< / strong> {{ticket.ticket_field_484179}}< br /> < strong> Uitbesteed:< / strong> {{ticket.ticket_field_483608}}< br /> < strong> Prioriteit:< / strong> {{ticket.priority}}< / td> < / tr> < tr> < td colspan = 6>< hr width = 100%noshade = noshade />< / td> < / tr> < tr> < td valign = top>< strong> Overeengekomen:< / strong>< / td> < td colspan = 5 rowspan = 2 valign = top>< p>& nbsp;< / p>< / td> < / tr> < tr> < td>& nbsp;< / td> < / tr> < tr> < td colspan = 6< hr width = 100%noshade = noshade />< / td> < / tr> < tr> < td valign = top>< strong> Handtekening voor akkoord:< / strong>< / td> < td colspan = 5< table width = 100%border = 0 cellspacing = 7 cellpadding = 7> < tr> < td width = 33%& nbsp;< / td> < td width = 33%& nbsp;< / td> < td width = 31%>& nbsp;< / td> < / tr> < tr> < td width = 33%>< hr noshade = noshade />< / td> < td width = 33%>< hr />< / td> < td>< hr />< / td> < / tr> < tr> < td width = 33%> {{ticket.requester.name}}< / td> < td width = 33%>基准:< / td> < td> Plaats:< / td> < / tr> < / table> < p>< br /> < / p>< / td> < / tr> < / table>> < input type = button value =打印Werkorder onClick =writeConsole(this.form.userInput.value) < / form>

编辑问题 / p>

这是我现在的,表单再次出现,但没有日期,为什么是这样?

我将再次发布代码:

已更改的javascript:

< script language =JavaScript> //获取今天的当前日期 var now = new Date(); //天数列表 var days = new Array('星期日','星期一','星期二','星期三','星期四','星期五','星期六' ; //数组列表 var months = new Array('January','February','March','April','May','June' '七月','八月','九月','十月','十一月','十二月'); //计算 var date =((now.getDate()< 10)?0:)+ now.getDate(); //计算四位数的年份。 函数fourdigits(number){ return(number< 1000)?数字+ 1900:数字} //一起加入 today = days [now.getDay()] +,+ months [now.getMonth()] ++ date +,+ (fourdigits(now.getYear())); //打印出数据。 // document.write(今天); //开始更改代码 document.getElementById(date)innerHTML = today; //结束修改后的代码 // End - > < / script>

解决方案

您好只需添加以下行 top.consoleRef.document.getElementById('date')。innerHTML = today;

之前 top.consoleRef.document.close()

并注释以下行。

// document.getElementById(date)。innerHTML = today;

这是因为你的date元素是文本框的值,它不是DOM的一部分。 因此,在文档上写入后,可以通过DOM访问。

beneath you see a piece of custom code for Zendesk. Everything works fine, till I want to implement a date/time snippet.

Normally the script works like this:

1 - there is a button which says "Print Ticket".

2 - The button has a onclick event to open a printer friendly page ready for printing.

After implementing the date/time code (what I didn't do well I believe) I only get the printable version of the ticket, but the time isn't displayed. (nothing happended really)

The only thing what happends is that the date and time are shown without the rest of the printable form.

I think the placemanet of the javascript is not in th right place, it needs to be in the head section which is generated also by javascript

Can anyone please help me with this? or point me in a vorm of example what to do?

<style> input.createtable { display:none; } </style> <script language="JavaScript"> // Get today's current date. var now = new Date(); // Array list of days. var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); // Array list of months. var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December'); // Calculate the number of the current day in the week. var date = ((now.getDate()<10) ? "0" : "")+ now.getDate(); // Calculate four digit year. function fourdigits(number) { return (number < 1000) ? number + 1900 : number; } // Join it all together today = days[now.getDay()] + ", " + months[now.getMonth()] + " " + date + ", " + (fourdigits(now.getYear())) ; // Print out the data. // document.write(today); // Begin altered code document.getElementById("date").innerHTML = today; // End altered code // End --> </script> <script language="JavaScript"> <!-- writeConsole = function(content) { top.consoleRef=window.open('','myconsole', 'width=800,height=800' +',menubar=0' +',toolbar=0' +',status=0' +',scrollbars=1' +',resizable=1') // top.consoleRef.document.open("text/html","replace"); top.consoleRef.document.writeln( '<html><head><title>Signature Page</title></head>' +'<style>th {color: #FFFFFF;border-bottom: 1px solid #000000;background-color:#CCCCCC;}tr {color: #000000;border-bottom: 1px solid #cccccc;}td.small {color: #000000; font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif;}td.large {color: #000000; font-size: 120%; font-family: Arial, Helvetica, sans-serif;font-weight: bold; text-align:center;}</style>' +'<link href="asset3.zendesk/stylesheets_old/zd_print.css?1270161524" media="print" rel="stylesheet" type="text/css" />' +'<body onLoad="self.focus()" style="background: white; font-size: 11px; font-family: Verdana, Arial, Helvetica, sans-serif">' +'<center><A HREF="javascript:window.print()">Print Werkorder</A></center>' +'<table width="100%"><tr><td align="left" valign="middle">' +'</td><br />' +'www.domain.nl<br />' +'Tel: 058-111111111<br />' +'E-mail info@domain.nl' +'</tr></table>' +content +'</body></html>' ) top.consoleRef.document.close() } //--> </script> <form> <input class="createtable" name=userInput type=textarea size="1" value="<table width=100% height=825 border=0 cellpadding=6 cellspacing=4> <tr> <th colspan=6><h1>WERKORDER NR#: {{ticket.id}}</h1></th> </tr> <tr> <td colspan=6><hr width=100% noshade=noshade /></td> </tr> <tr> <td width=13% valign=top><strong>Klantinformatie:</strong></td> <td width=87% align=left valign=top><p><strong>Datum: <div id=date></div> <br /> Naam</strong>: {{ticket.requester.name}}<br /> <strong>Bedrijf:</strong> {{ticketanization.name}}<br /> <strong>Telefoonnummer:</strong> {{ticket.ticket_field_484140}}<br /> <strong>E-mail:</strong> {{ticket.requester.email}}</p></td> </tr> <tr> <td valign=top><strong>In ontvangst genomen:</strong></td> <td align=left valign=top><strong>Merk &amp; Model:</strong> {{ticket.ticket_field_483591}}<br /> <strong>Hardware Type:</strong> {{ticket.ticket_field_484179}}<br /> <strong>Uitbesteed:</strong> {{ticket.ticket_field_483608}}<br /> <strong>Prioriteit:</strong> {{ticket.priority}}</td> </tr> <tr> <td colspan=6><hr width=100% noshade=noshade /></td> </tr> <tr> <td valign=top><strong>Overeengekomen:</strong></td> <td colspan=5 rowspan=2 valign=top><p>&nbsp;</p></td> </tr> <tr> <td>&nbsp;</td> </tr> <tr> <td colspan=6><hr width=100% noshade=noshade /></td> </tr> <tr> <td valign=top><strong>Handtekening voor akkoord:</strong></td> <td colspan=5><table width=100% border=0 cellspacing=7 cellpadding=7> <tr> <td width=33%>&nbsp;</td> <td width=33%>&nbsp;</td> <td width=31%>&nbsp;</td> </tr> <tr> <td width=33%><hr noshade=noshade /></td> <td width=33%><hr /></td> <td><hr /></td> </tr> <tr> <td width=33%> {{ticket.requester.name}} </td> <td width=33%>Datum:</td> <td>Plaats:</td> </tr> </table> <p><br /> </p></td> </tr> </table>"> <input type=button value="Print Werkorder" onClick="writeConsole(this.form.userInput.value)" > </form>

Edit question

This is what I have now, the form appears again, but without a date, why is this?

I'll post in short the code again:

the altered javascript:

<script language="JavaScript"> // Get today's current date. var now = new Date(); // Array list of days. var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); // Array list of months. var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December'); // Calculate the number of the current day in the week. var date = ((now.getDate()<10) ? "0" : "")+ now.getDate(); // Calculate four digit year. function fourdigits(number) { return (number < 1000) ? number + 1900 : number; } // Join it all together today = days[now.getDay()] + ", " + months[now.getMonth()] + " " + date + ", " + (fourdigits(now.getYear())) ; // Print out the data. // document.write(today); // Begin altered code document.getElementById("date").innerHTML = today; // End altered code // End --> </script>

解决方案

Hi Just add following line top.consoleRef.document.getElementById('date').innerHTML = today;

before top.consoleRef.document.close()

and comment the following line.

//document.getElementById("date").innerHTML = today;

This is because your date element is as a value of textbox and it is not a part of DOM. So after writing it on document, you can access it through DOM.

更多推荐

date.getElementById的日期时间不起作用

本文发布于:2023-11-22 19:07:12,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   日期   时间   date   getElementById

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!