I've the following input tag
我有以下输入标记
<input name="PostBack.Contract.ID" type="hidden" value="foo" />
and I need to change the value. I'm trying using the following statement but it doesn't work
我需要改变价值。我正在尝试使用以下语句,但它不起作用
$("input[type=hidden].PostBack.Contract.ID");
I get the following result
我得到以下结果
[]
What I'm doing wrong?
我做错了什么?
3 个解决方案
#1
1
Change
$("input[type=hidden].PostBack.Contract.ID");
To:
$('input[name="PostBack.Contract.ID"]');
Here is the DEMO
这是DEMO
Note that I have changed the input type to 'text' for demonstration.
请注意,我已将输入类型更改为“text”以进行演示。
#2
1
Select the element by name
using attribute selectors. Check out following code ( I have changed input type to text
so output can be seen easily ):
使用属性选择器按名称选择元素。查看以下代码(我已将输入类型更改为文本,因此可以轻松查看输出):
$(document).ready(function(){
$("input[name='PostBack.Contract.ID']").val("bar");
});//
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input name="PostBack.Contract.ID" type="text" value="foo" />
#3
0
You can use jquery hidden-selector
您可以使用jquery隐藏选择器
$( "input:hidden[name='PostBack.Contract.ID']" ).val() // Note the quotes
#1
1
Change
$("input[type=hidden].PostBack.Contract.ID");
To:
$('input[name="PostBack.Contract.ID"]');
Here is the DEMO
这是DEMO
Note that I have changed the input type to 'text' for demonstration.
请注意,我已将输入类型更改为“text”以进行演示。
#2
1
Select the element by name
using attribute selectors. Check out following code ( I have changed input type to text
so output can be seen easily ):
使用属性选择器按名称选择元素。查看以下代码(我已将输入类型更改为文本,因此可以轻松查看输出):
$(document).ready(function(){
$("input[name='PostBack.Contract.ID']").val("bar");
});//
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input name="PostBack.Contract.ID" type="text" value="foo" />
#3
0
You can use jquery hidden-selector
您可以使用jquery隐藏选择器
$( "input:hidden[name='PostBack.Contract.ID']" ).val() // Note the quotes