jQuery"事件监听器"不使用来自数据库的数据

时间:2017-07-31 18:52:33

标签: javascript php jquery mysqli

我从我的数据库中提取文字并插入 P TAG ,其 作为我的监听器,但是当我点击文本时,JavaScript没有任何反应。

网站http://fluentabc.com/edit.php

这是图片: enter image description here

HTML

<p class="sec_text" id="sec_1" data-reveal-id="myModal">
  <?php 
  $query = mysqli_query($con,"SELECT * FROM site_edit WHERE site_sec='MainTitle'");

  while($qt = mysqli_fetch_array($query)){
  echo $MainTitle = $qt['site_txt']; // <-- I WANT TO CLICK ON THIS TEXT
  }                         
  ?>                      
</p>

JS

$(document.body).on('click', '.sec_text' ,function(){

     var txt = $(this).text();
     var sec_id = $(this).parent().attr('id');

     $("#curEditing").html("Your Editing : " + sec_id);
     $("#sec_edit_name").val(sec_id);

     tinyMCE.activeEditor.setContent(txt);

}); 

2 个答案:

答案 0 :(得分:-1)

只需更新您的html代码100%正常工作:

您的输出应该是这样的:

<p class="sec_text" id="sec_1" data-reveal-id="myModal">Learn English Today!</p>

更新HTML

<p class="sec_text" id="sec_1" data-reveal-id="myModal">
  <?php 
  $query = mysqli_query($con,"SELECT * FROM site_edit WHERE site_sec='MainTitle'");

  while($qt = mysqli_fetch_array($query)){
    echo $MainTitle = strip_tags($qt['site_txt']); // <-- I WANT TO CLICK ON THIS TEXT
  }                         
  ?>                      
</p>

enter image description here

答案 1 :(得分:-1)

/Applications/MAMP/bin/php/php5.6.10/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin