简体   繁体   English

Codeigniter日期选择器不起作用

[英]Codeigniter Date picker is not working

I need to add date to the form input field, but in codeigniter it is not working,here is my code in view, I don't know why it is not working, I have link web links also. 我需要在表单输入字段中添加日期,但是在codeigniter中它不起作用,这是我的代码,我不知道为什么它不起作用,我也有链接Web链接。 it is only not working in codeigniter. 它仅在codeigniter中不起作用。 this page is loaded using ajax .I think it would be the reason for the problem,how can I fix it???? 此页面是使用ajax加载的 。我认为这是问题的原因,我该如何解决?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>


<div id="content">

 <h2>Payment Details.</h2>
<?php
          $this->load->helper('form');
          $attributes = array('method'=>'post','name'=>'payments','id'=>'payments');
          echo form_open_multipart('',$attributes);?>
    <?php //echo form_open_multipart('payments/insert_payment');?>
    <label>Payee Name: </label> <?php echo form_input('payee_name');?><br/><br/>

    <label>Address: </label> <?php echo form_input('address');?><br/><br/>

    <label>Account No: </label> <?php echo form_input('account_no');?><br/><br/>

    <label>Bank Name: </label> <?php echo form_input('bank_name');?><br/><br/>

    <label>Branch: </label> <?php echo form_input('branch');?><br/><br/>

    <label>Amount: </label> <?php echo form_input('amount');?><br/><br/>
    <label>Pick a Check Date: </label> <?php
                    $data = array(
                      'name'=> 'check_date',
                      'id' => 'datepicker',
                      'placeholder' => 'date',
                    );
echo form_input($data);?><br/><br/>

    <label>Check Number: </label> <?php echo form_input('check_number');?><br/><br/>        

    <input type="submit" name="submit" value="Next"/>
<?php echo form_close(); ?>

You are trying to add two jquery files with different versions 您正在尝试添加两个具有不同版本的jquery文件

thats why the datepicker is confused which jquery version can be used 多数民众赞成在为什么datepicker混淆可以使用哪个jquery版本

please add jQuery.noConflict() before the document.ready function 请在document.ready函数之前添加jQuery.noConflict()

Hope this helps :) 希望这可以帮助 :)

<script>
jQuery.noConflict();
$(function() {
$( "#datepicker" ).datepicker();
});
</script>

Datepicker is not working because #datepicker didn't exist yet. #datepicker无法正常工作,因为#datepicker还不存在。 You could make this work by moving ('#datepicker').datepicker() to after the point in the code where it( #datepicker ) is created. 您可以通过将('#datepicker').datepicker()到创建代码( #datepicker )的点之后,来完成此工作。

Debug as following 如下调试

1> Check console. 1>检查控制台。

2> Use inspect element for actual Id ( lots of frameworks changed it internally). 2>使用inspect元素作为实际ID(许多框架在内部对其进行了更改)。

3> Try to put $( "#datepicker" ).datepicker(); 3>尝试放入$( "#datepicker" ).datepicker(); at end of file 在文件末尾

You are adding date picker to the id 您正在将日期选择器添加到ID

$( "#datepicker" ).datepicker();

But where is this Id. 但是这个ID在哪里。 You should add datepiker to the view where the id is available and add the respective javascript file also 您应将datepiker添加到ID可用的视图中,并同时添加相应的javascript文件

View: 视图:

$this->load->helper(array('form')); 

Controller: 控制器:

function datepicker(){
    $this->load->view('datepicker');
}

jQuery: jQuery的:

$(function() {
$( "#datepicker" ).datepicker();
});

I saw alot of problems 我看到了很多问题

  1. save the style sheet inside css folder(optional) your css should inside your ci folder 将样式表保存在css文件夹中(可选),将css保存在ci文件夹中
  2. your href in css is not the right code, if your linking css do the code below 如果您的链接CSS执行以下代码,则您在CSS中的href不是正确的代码

      <link rel="stylesheet" href="<?php echo base_url();?>css/style.css" />` 

make sure your base_url is correct. 确保您的base_url是正确的。 To see if this correct try to echo base_url(); 看看是否正确尝试echo base_url();

hope this help you 希望这对你有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM