将Datepicker分配给javascript变量(Assigning Datepicker to javascript variable)

编程入门 行业动态 更新时间:2024-10-25 16:23:58
将Datepicker分配给javascript变量(Assigning Datepicker to javascript variable)

我有一些非常简单的js工作,用户在文本框中输入信息,并使用单击功能在文档的另一个区域重新填充输入。 某些输入字段需要日期,我希望它们显示为日期选择器。 我已尝试按照本指南中的说明将datepicker设置为文档头部的样式http://javarevisited.blogspot.ca/2013/10/how-to-use-multiple-jquery-ui-date.html但它不起作用。

这是因为变量Id覆盖了类ID吗? 我可以在脚本中分配datepicker功能吗?

<script type = "text/javascript"> function sayHi(){ var BPCName = document.getElementById("BPCName"); var OUTBPC = document.getElementById("OUTBPC"); var name = BPCName.value; OUTBPC.value = " " +name+ "" } // end sayHi <style> .datepicker {}</style> <script> $(function() { $( "#datepicker" ).datepicker(); }); </script>

<form action = ""> <fieldset> <label>Start Date: </label> <input type = "text" class=datepicker id = "BPCName" />

<h1>TEST</h1> <form action = ""> <fieldset> <label>Start Date: </label> <input type = "text" class=datepicker id = "BPCName" />

I have some very simple js working where a user enters info in a textbox, and the input is repopulated in another area of the document with a click function. Some of the input fields require dates, and I would like them to appear as date pickers. I have tried to set the datepicker as a style in the head of the doc as instructed in this guide http://javarevisited.blogspot.ca/2013/10/how-to-use-multiple-jquery-ui-date.html but it isn't working.

Is this because the variable Id overrides the class ID? Can I assign the datepicker function in the script?

<script type = "text/javascript"> function sayHi(){ var BPCName = document.getElementById("BPCName"); var OUTBPC = document.getElementById("OUTBPC"); var name = BPCName.value; OUTBPC.value = " " +name+ "" } // end sayHi <style> .datepicker {}</style> <script> $(function() { $( "#datepicker" ).datepicker(); }); </script>

<form action = ""> <fieldset> <label>Start Date: </label> <input type = "text" class=datepicker id = "BPCName" />

<h1>TEST</h1> <form action = ""> <fieldset> <label>Start Date: </label> <input type = "text" class=datepicker id = "BPCName" />

最满意答案

你只需要在标题中调用Jquery和JqueryUI然后使用它

$("input.datepicker").datepicker(); //this code will set all your inputs with "datepicker" class, to appear the datepicker //from JqueryUI

你应该把

class="datepicker"

不是简单的

class=datepicker

you just need to call Jquery and JqueryUI in your headers then use this

$("input.datepicker").datepicker(); //this code will set all your inputs with "datepicker" class, to appear the datepicker //from JqueryUI

and you should put

class="datepicker"

not simply

class=datepicker

更多推荐

本文发布于:2023-08-07 23:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466398.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   javascript   Datepicker   Assigning   variable

发布评论

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

>www.elefans.com

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