将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将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