dtewnsdf47253 2014-11-21 12:29
浏览 24
已采纳

PHP的JavaScript问题

I am totally new in php, so my opology if this question seems weird to you.

I have one php file (index.php) something like,

echo "
    <div>  
        <FORM name='myform' id='myform' method='post' action=''>

        // I fetch data from mysql and populate dropdown list. Tha't work fine.
        // Then I have one submit button when I click on that

        echo "<button id='showButton' type='submit'> Show </button>"; 

        </FORM>
";

Then I have one process.js file something like,

$(document).ready(function() {

    $('#showButton').click(function () {

        // Here I make one AJAX call to php file (fetch_more_data.php), which fetch more data from database
        // This also works fine

    });

});

In fetch_more_data.php I fetch more data and display in table using

echo "
    <script type = 'text/javascript' src = 'edit.js'></script>

    <table ...>

    <td>
        <button id="myButton"></button>
    </td>

    </table>

";

This is also work fine. but I want to edit one table cell and for that I need to write some java script code. I want to write on click function for myButton in Javascripr, for that I have written on edit.js file,

$(document).ready(function() {

    $('#myButton').click(function () {

        alert('Hello');

    });

});

The problem is $('#myButton').click(function () never called. I have spent long time but being a beginner my search options are limited. I would appriciate if someone solve this problem.

Regards,

  • 写回答

4条回答 默认 最新

  • doubi3929 2014-11-21 12:34
    关注

    try calling it like this:

    $(document).ready(function(){
      $(document).on('click', '#myButton', function(){
        alert('hi');
      });
    });
    

    hope this helped

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果