当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Get input value

问题描述:

I have the following input

<input value="25" data-hidden-value="25" name="associations[agencies][ids][]"

data-hidden-name="associations[agencies][ids][]" class="string" type="hidden">

This input is dynamically generated, and don't have any ID. I'm trying to get the value using the following code:

campaignId = $("input[name='associations[agencies][ids][]]'").val();

But I always get undefined.

网友答案:

You have wrong selector. Try this

$('input[name="associations[agencies][ids][]"]').val();
网友答案:

The problem is with your selector - you closed the first opening [ in the wrong place. Proper line should be:

campaignId = $("input[name='associations[agencies][ids][]']").val();

Hope that helps ;)

网友答案:

You have a syntax error at input[name='xxx'] , the last single quote should be inside the last ]

change

$("input[name='associations[agencies][ids][]]'")

to

$("input[name='associations[agencies][ids][]']")

网友答案:

you just need to change the value of name that you are provided $("input[name='xyz']") you just misplace the ] inside the '

$("input[name='associations[agencies][ids][]]'").val()

to

 $("input[name='associations[agencies][ids][]']").val()
分享给朋友:
您可能感兴趣的文章:
随机阅读: