Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery获取选定/同一类数据的单个值_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript JQuery获取选定/同一类数据的单个值

Javascript JQuery获取选定/同一类数据的单个值,javascript,jquery,ajax,Javascript,Jquery,Ajax,如何获取data-id的每个值。我需要选择时,它只传递一个值。我希望你能明白我的意思。谢谢 <tr> <td>Satu</td> <td> <a class="bedit" data-id="11">edit</a> </td> </tr> <tr> <td>dua</td> <td>

如何获取data-id的每个值。我需要选择
时,它只传递一个值。我希望你能明白我的意思。谢谢

<tr>
    <td>Satu</td>
    <td>
        <a class="bedit" data-id="11">edit</a>
    </td>
</tr>
<tr>
    <td>dua</td>
    <td>
        <a class="bedit" data-id="12">edit</a>
    </td>
</tr>
<tr>
    <td>tiga</td>
    <td>
        <a class="bedit" data-id="13">edit</a>
    </td>
</tr>

佐藤
编辑
杜阿
编辑
蒂加
编辑
试试这个

$('a.bedit').on('click', function () {
    alert($(this).data('id'));
});
像这样添加到数组中

var dataID = [];
$('a.bedit').each(function () {
    dataID.push($(this).data('id')); //adds into array
});
试试这个

$('a.bedit').on('click', function () {
    alert($(this).data('id'));
});
像这样添加到数组中

var dataID = [];
$('a.bedit').each(function () {
    dataID.push($(this).data('id')); //adds into array
});

您可以尝试使用这个简单的javascript代码来获取data-id。 将此函数置于window-onload或body-onload中:-

function load() {
    var elemDom= document.getElementsByClassName('bedit');

    for(var count=0; count < elemDom.length; count++)
    {
        elemDom[count].onclick = function() {
            alert(this.getAttribute('data-id'));
        };
    }
}
函数加载(){
var elemDom=document.getElementsByClassName('bedit');
对于(var count=0;count
您可以尝试使用这个简单的javascript代码来获取数据id。 将此函数置于window-onload或body-onload中:-

function load() {
    var elemDom= document.getElementsByClassName('bedit');

    for(var count=0; count < elemDom.length; count++)
    {
        elemDom[count].onclick = function() {
            alert(this.getAttribute('data-id'));
        };
    }
}
函数加载(){
var elemDom=document.getElementsByClassName('bedit');
对于(var count=0;count