javascript - JQuery datatable link onclick event - Stack Overflow

I have a jquery datatable that contains multiple columns and rows as below.<table><thead>&l

I have a jquery datatable that contains multiple columns and rows as below.

<table>
    <thead>
        <tr>
            <td>Name</td>
            <td>Class</td>
            <td>Action</td>
            <td>Score</td>
            <td>Corrected Score</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Student1</td>
            <td>Math</td>
            <td><a href="#">Add 5</a>
            </td>
            <td>73</td>
            <td>
                <input type="text" id="1_final_score" />
            </td>
        </tr>
        <tr>
            <td>Student2</td>
            <td>Biology</td>
            <td><a href="#">Add 5</a>
            </td>
            <td>84</td>
            <td>
                <input type="text" id="2_final_score" />
            </td>
        </tr>
        <tr>
            <td>Student3</td>
            <td>History</td>
            <td><a href="#">Add 5</a>
            </td>
            <td>50</td>
            <td>
                <input type="text" id="3_final_score" />
            </td>
        </tr>
    </tbody>

When i click on the "Add 5" link, I want to add 5 to the score in the corresponding row and insert the result in the final score input field. I have tried using the jquery row-select feature, but am unable to figure out how to acplish the above.

I have a jquery datatable that contains multiple columns and rows as below.

<table>
    <thead>
        <tr>
            <td>Name</td>
            <td>Class</td>
            <td>Action</td>
            <td>Score</td>
            <td>Corrected Score</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Student1</td>
            <td>Math</td>
            <td><a href="#">Add 5</a>
            </td>
            <td>73</td>
            <td>
                <input type="text" id="1_final_score" />
            </td>
        </tr>
        <tr>
            <td>Student2</td>
            <td>Biology</td>
            <td><a href="#">Add 5</a>
            </td>
            <td>84</td>
            <td>
                <input type="text" id="2_final_score" />
            </td>
        </tr>
        <tr>
            <td>Student3</td>
            <td>History</td>
            <td><a href="#">Add 5</a>
            </td>
            <td>50</td>
            <td>
                <input type="text" id="3_final_score" />
            </td>
        </tr>
    </tbody>

When i click on the "Add 5" link, I want to add 5 to the score in the corresponding row and insert the result in the final score input field. I have tried using the jquery row-select feature, but am unable to figure out how to acplish the above.

Share Improve this question edited May 18, 2015 at 6:24 Afsar 3,1242 gold badges27 silver badges35 bronze badges asked May 18, 2015 at 6:05 DanDan 632 silver badges9 bronze badges 1
  • check this @Dan you can use this jsfiddle/yecmqf5z – Junaid Ahmed Commented May 18, 2015 at 6:26
Add a ment  | 

3 Answers 3

Reset to default 4
$(document).ready(function () {
$('table').find('a').click(function () {
    var original = parseInt($(this).parents('tr').find('td:nth-child(4)').text()) + 5;

    $(this).parents('tr').find('input[type=text]').val(original);

   });

});

You can try this:

$(document).ready(function(){
    $("a").on("click", function(){
        var num=parseInt($(this).closest("td").next("td").text());
        num=num+5;
        $(this).closest("td").next("td").text(num);
        $(this).closest("tr").find("input").val(num);

    });
});

FIDDLE

Try with this

$('a:contains("Add 5")').click(function(){
    $(this).parents('tr').find('td input:text').val(+$(this).parent().next('td').text() + 5 )
 });

FIddle : http://jsfiddle/2n0bevxo/172/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745318726a4622341.html

相关推荐

  • javascript - JQuery datatable link onclick event - Stack Overflow

    I have a jquery datatable that contains multiple columns and rows as below.<table><thead>&l

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信