我有一个多页文档,但我一直在显示 html 并对一个 php 文件中的单个页面进行验证:
<div id="checkPage" data-role="page">
  <div data-role="header">
    <h1>Page Title</h1>
  </div>
  <div data-role="content">
    <?php
    $form = $_REQUEST['form'];  //this is simply a hidden input in my form that I reference to know if a form submission has occurred
    if($form) {
      $res = process();
      if(is_array($res)) { //if the data is an array then it is an array of errors that I will display to the user
        $html = page($res); 
      } else {
        $html = $res;  //if the data is not an array then it is confirmation html that the request was successful.
      }
    } else {
      $html = page();
    }
    echo $html;
    ?>
  </div>
</div>
在我的 page() 函数中,我在我的 HTML 之后附加了一些 jquery:
$detail .= chr(10) . '<script type="text/javascript">';
$detail .= chr(10) . '$( "#checkPage" ).bind( "pageinit",function(event){';
$detail .= chr(10) . '  $("#txtAmount").change(function(){';
$detail .= chr(10) . '    alert("INSIDE");';
$detail .= chr(10) . '  });';
$detail .= chr(10) . '});';
$detail .= chr(10) . '</script>';
return $detail;
当我导航到我的页面然后输入(并离开)金额文本框时,我看到了警报。如果我单击页面上的取消按钮(我被重定向到另一个页面)然后通过菜单超链接再次返回并再次输入(并离开)文本框,我也会看到警报。但是,如果我提交表单,发现验证错误并重新显示页面,则不会再次设置 pageinit。即使我离开 pageinit 逻辑,也不再设置更改事件。
我究竟做错了什么?我很感激我能得到的任何帮助。