我想通过一个onchange事件调用多个范围

时间:2018-07-05 04:55:18

标签: php jquery html

如何通过单个onchange事件调用多个函数?我想通过一个onchange调用多个范围。

JS代码:

<script type="text/javascript">
    function update() {
        var price = document.getElementById('Totalprice').innerHTML;
        var quantity = document.getElementById('quantitys').value;
        var Tprice = (price * quantity);
        document.getElementById('prices').innerHTML = Tprice;
    }
</script> 

PHP代码:

<span id="Totalcosttt2" style="display:none" class="checks"> 
    <?php
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "db";
    $con = mysqli_connect('localhost', 'root', '', 'db')or die('cannot connect');
    $add = mysqli_query($con, 'select packaged.id, packaged.package_price, packages.hours, packaged.package_price - packages.hours as Total from packaged join packages on packaged.id = 3 and packages.pid=3');
    while ($row1 = mysqli_fetch_assoc($add)) {
        echo $row1['Total'];
    }
    ?>
</span>
<textarea id="quantitys" class="quan" onChange="update()">1</textarea>

1 个答案:

答案 0 :(得分:1)

如果要跟踪跨度元素的动态变化,可以使用事件“ DOMSubtreeModified”进行跟踪:

$('span').on('DOMSubtreeModified',function(){

警报(“已更改”) });

这会将更改事件添加到页面上的所有跨度元素enter code here。 如果您只想跟踪某些span标签的变化,请给它们一些类(例如class-span),然后执行以下操作:

$('.class-span').on('DOMSubtreeModified',function(){

警报(“已更改”) });