Webpack:函数未定义

时间:2016-08-16 13:04:52

标签: javascript typescript javascript-events webpack electron

我使用webpack进行模块加载。一切正常,除了点击来自html的事件。

例如我想这样做;

 <?php
  $datetime = new \DateTime();

  $listItem = array('<li class="active">', '</li>');



  $times = array(
    1 => date( $row_DetailRS1['monO'] ). " ". date( $row_DetailRS1['monC'] ),
    2 =>  date( $row_DetailRS1['tueO'] ) . " ". date( $row_DetailRS1['tueC'] ),
    3 =>  date( $row_DetailRS1['wedO'] ) . " ". date( $row_DetailRS1['wedC'] ),
    4 =>  date( $row_DetailRS1['thurO'] ) . " ". date( $row_DetailRS1['thurC'] ),
    5 =>  date( $row_DetailRS1['friO'] ) . " ". date( $row_DetailRS1['friC'] ),
    6 =>  date( $row_DetailRS1['satO'] ) . " ". date( $row_DetailRS1['satC'] ),
    7 =>  date( $row_DetailRS1['sunO'] ) . " ". date( $row_DetailRS1['sunC'] ) );





  $html = "<table>";
  $html .= "<tr> <td>Days</td> <td> </td> <td></td>   <td>Business Hours</td></tr>";
  $i = 1;





  foreach ($times as $key => $value):



    $m = $datetime->format('N');


      $html .= "<tr>";
      $html .= "<td>". $datetime->format('D')."</td>";
      $html .= "<td>". " "."</td>";
      $html .= "<td>". " "."</td>";
      $html .= "<td>".$times[$m]."</td>";
      $html .= "</tr>";

      $datetime->add(new \DateInterval('P1D'));



      $i++;




  endforeach;
  $html .= "</table>";
  echo $html;



 ?>

但是每当我点击该元素时都会收到错误;

<li id="a" onclick="f(this.id)">lorem</li>

编译的js文件(功能部分);

Uncaught ReferenceError: f is not defined

然后我意识到,实际上它是在一个全球的webpack函数中;

    function f(d) {
       console.log(d);
    }

我认为这就是问题的原因。

我该如何解决这个问题?

P.S。:我尝试从代码中处理事件,它也没有用。

0 个答案:

没有答案