下面的jquery没有't在chrome中工作,而在firefox中工作

following jquery doesn't work in chrome while its works in firefox

本文关键字:工作 chrome firefox 而在 jquery 没有      更新时间:2023-09-26

HTML

<tr class="txtMult"> 
    <td>2</td> 
    <td>
        <select style="width: 180px;" class="select" id="select2"> 
            <?PHP foreach($results as $row) 
                echo"<option onclick='myAjaxFunction(this);' value=" . $row->itemName .">" . $row->itemName . "</option>"; 
            ?>  
        </select>
    </td> 
    <td><input type='text' class='val1' name="123"></td> 
    <td><input type='text' class='val2' id="2"></td> 
    <td><input type='text' class='multTotal' value='0.00' required></td> 
</tr> 

Javascript:

var d = 1;   
function myAjaxFunction() { 
    var string = $('#select' + d + '').val();
    $.post("http://localhost/online_stock_system/new_cont/add", {
        input: string
    }, function (data) {
        $('#' + d + '').val(data);
        // $('#select'+d+'').attr('disabled','');
        d++;
    });  
}

这段代码包含在new.js文件中,但它在chrome上不工作,而在firefox上工作。

您在选项标记上使用onclick。这不是支持的事件。你可以在这里看到另一个答案来了解更多信息。

如果您想在更改值时触发函数,只需使用.change()

$('#select2').on('change', function() {
  myAjaxFunction(this);
});

$('#select2').on('change', function() {
    var string = $('#select' + d + '').val();
    $.post("http://localhost/online_stock_system/new_cont/add", {
        input: string
    }, function (data) {
        $('#' + d + '').val(data);
        d++;
    });  
});