在javascript按钮中添加功能

时间:2016-02-07 21:45:37

标签: javascript php jquery mysql phpmyadmin

我希望我的*有一个功能,当我点击Post按钮时,表格中的数据将被插入到数据库中。

int main()
{
    double Numbers[NMAX] = {31.2, 29.7, 53.5, 69.0, 23.7, 71.8, 49.3, 52.9, 51.3, 57.1};
    bool change[NMAX] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

    // note this top counter, i, counts down
    int counter = 0;
    for (int i=NMAX-1; i>0; i--)
    {
        //and this counter, j, only goes as far as the current i value 
        // it means it doesn't go over the elements that have already 'bubbled up' to the end of the array
        for (int j=0; j<i; j++)
        {
            double temp;
            // Compare 2 values - increment a counter here
            counter++;

            if (Numbers[j]>Numbers[j+1])
            {
                temp = Numbers[j];
                Numbers[j]= Numbers[j+1];
                Numbers[j+1]= temp;
                cout << "Array: " << endl;
                change[j] = true;
                change[j + 1] = true;

                for (int i = 0; i < 10; i++)
                {
                    cout << Numbers[i] << ", ";
                }
            }
        }
    }

    // display the sorted array:
    cout << endl;
    cout<<"ARRAY CONTENTS SORTED, IMPLEMENTATION 1 "<<endl;
    for (int i=0; i<NMAX; i++)
    {
        cout<<Numbers[i]<<endl;
    }
    //Display the values of the counter after the whole sort
    return 0;
}

1 个答案:

答案 0 :(得分:0)

你需要ajax来实现这一目标。我将使用Jquery这样做:

<强> JS

$(function(){
  $('.btn-post-announcement').click(function(){ // on button pressed
    var data = {};
    var count = 0;
   $('td').each(function(){        // for each td 
     data[count++] = $(this).text(); // collect the text inside it
   })
    $.post("url.php", data, function(resp){ // send the collected data to the PHP 
       console.log(response)
    })
  })
})

<强> url.php

<?php
 var_dump($_POST);