jquery: percentage of two numbers

后端 未结 5 562
情深已故
情深已故 2021-01-12 16:06

EDITED

Thank you for everyone who offered support... the best working script I will share with you in hope that I could help others who is looking f

5条回答
  •  不思量自难忘°
    2021-01-12 17:02

    You have few problems,

    1. ? after closing parenthesis of text function.
    2. Repeated id price1 and price2 for both div and textboxes
    3. If you want input from textbox then you should use val() instead of text()

    Fixed you code

    Live Demo

    HTML

    Javascript

    $("#btnCal").click(function() {
        $("#rate").val(function() {
            var result = parseInt($("#price1").val()) * 100 / parseInt($("#price2").val());
            if (!isFinite(result)) result = 0;
            return result;
        });
    });​
    

提交回复
热议问题