Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.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 js。使用id获取多个值_Javascript_Html_Selector - Fatal编程技术网

Javascript js。使用id获取多个值

Javascript js。使用id获取多个值,javascript,html,selector,Javascript,Html,Selector,我试过很多方法。。。 不确定如何使用目标获取每个ID的值。我认为ID之间有空格等问题 我找到了解决这个问题的办法 刚刚使用的: function handleInfo() { $('#accordion').on('click','.info-actions',(event) => { let target = $(event.target).attr('id'); console.log(target); //this prints the id

我试过很多方法。。。
不确定如何使用目标获取每个ID的值。

我认为ID之间有空格等问题

我找到了解决这个问题的办法

刚刚使用的:

function handleInfo() {
    $('#accordion').on('click','.info-actions',(event) => {
        let target = $(event.target).attr('id');
        console.log(target);
//this prints the id fine.

//let x = $('.control').attr('value');
//let x = $(`#a${target}`);
//let x = $(`#a${target}`);
//let x = $('#a${target}').val();
        console.log(x);

//..... then going to use ajax to connect controller.(Which I can handle)
})}

等等。

您能告诉我们您尝试了什么吗?//让x=$('.control').attr('value')//设x=$(
#a${target}
)//设x=$(
#a${target}
)//设x=$('#a${target}').val();您可以通过标记名来查询它们,而不是通过id来确定目标。。。类似于
$(this).children('input').forEach()
$(this)
function handleInfo() {
    $('#accordion').on('click','.info-actions',(event) => {
        let target = $(event.target).attr('id');
        console.log(target);
//this prints the id fine.

//let x = $('.control').attr('value');
//let x = $(`#a${target}`);
//let x = $(`#a${target}`);
//let x = $('#a${target}').val();
        console.log(x);

//..... then going to use ajax to connect controller.(Which I can handle)
})}
var name = "a" + target;
var nameVal = document.getElementById(name).value;