2017-01-27 76 views
1

我想使用Apex inputText控件从用户输入日期使用jQuery日期选取器。使用Jquery Date Picker与VisualForce Apex inputText

下面给出了页面代码和使用的javascript函数,当我使用HTML输入控件但不能使用Apex inputText控件时,代码在我看来工作得很好。

<apex:page showHeader="false" id="mypage" docType="html-5.0" controller="ControllerCalculateIncentive" sidebar="false" standardStylesheets="false"> 
    <html> 
    <head> 
    <apex:stylesheet value="{!URLFOR($Resource.styles, 'bootstrap.css')}" /> 
    <apex:stylesheet value="{!URLFOR($Resource.styles, 'scrum.css')}" /> 
    <apex:stylesheet value="{!URLFOR($Resource.styles, 'jquery-ui.css')}" /> 
    <apex:stylesheet value="{!URLFOR($Resource.styles, 'font-awesome.css')}" /> 
    <apex:includeScript value="{!URLFOR($Resource.styles, 'jquery-1.11.1.js')}"/> 
    <apex:includeScript value="{!URLFOR($Resource.styles, 'bootstrap.js')}"/> 
    <apex:includeScript value="{!URLFOR($Resource.styles, 'jquery.min.js')}"/> 
    <apex:includeScript value="{!URLFOR($Resource.styles, 'jquery-ui.js')}"/>  
    <script type="text/javascript"> 
     var j$ = jQuery.noConflict(); 
     j$(document).ready(function(){   
      var v= '{!$Component.mypage:frm:StartDate}'; 
      j$(v).datepicker({ 
       dateFormat: 'dd-mm-yyyy', 
       changeMonth: true, 
       changeYear: true}); 

      }); 
    </script> 
    </head> 
    <body> 
    <apex:form id="frm"> 
    <apex:inputText id="StartDate" value="{!StartDate}" ></apex:inputText> 
    <apex:form> 
    </body> 
    </html> 
</apex:page> 

回答

0

请您用下面的代码试试:

j$(document).ready(function(){   
    var v= '#StartDate'; //putting id of the input field directly 
    j$(v).datepicker({ 
    dateFormat: 'dd-mm-yyyy', 
    changeMonth: true, 
    changeYear: true}); 

}); 
+0

这是<顶点:inputText的/>控制不是HTML

+0

但根据文档HTML INPUT将使用相同的ID创建。看到这个例子:https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_inputText.htm – vijayP

+0

感谢您的答复,但它仍然无法正常工作 –

1

使用此行

j$('input[id$="StartDate"]') 

这里面使用jQuery的控制