0

我正在向我正在创建的表单添加一个 div。我想用这个函数来做这个on(),但我似乎无法让它工作。据我了解,您必须使用事件,但是有没有办法从添加的 div 中创建事件。我一直在尝试的代码是带有“点击”事件的,但这并不是我真正想要的。在第一次单击后添加了日期选择器,但根本没有添加 buttonImage。我需要它在第一次点击时工作。这是我现在正在使用的代码:

  $('#switcher-panel').on('click', 'table tr td input', function(){
    $('.datepicker').datepicker({
      buttonImage: "images/calendar.png"
    });
  });

这是我正在使用的html:

<table class="table table-hover" data-controller="rank">
  <thead>
    <tr>
      <th colspan="4" align="left"><h2> Boy Scout Rank</h2></th>
    </tr>
    <tr>
      <th>Number</th>
      <th>Requirements</th>
      <th>Completed</th>
      <th>Date</th>
    </tr>
  </thead>
  <tbody>
    <tr data-name="one_li">
      <td>1</td>
      <td>
        Req
      </td>
      <td>
        <input class="datepicker"/>
      </td>
    </tr>
  </tbody>
</table>

我不明白如何处理这个。任何帮助都会很棒。

4

2 回答 2

0

从您上面的代码来看,看起来您并没有添加新的<div />

如果不是,则不需要添加事件(单击)处理程序 - http://jsfiddle.net/ZNR7P/

你应该能够做到:

$(function() {

    $('.datepicker').datepicker();

});​
于 2012-11-23T01:07:51.147 回答
0
$(function(){

    $('.datepicker').datepicker({
        showOn:"button", // or "both" if you want the input to trigger the datepicker too
        buttonImage: "images/calendar.png"
    });

})
于 2012-11-23T01:17:51.217 回答