使用 Jquery $('#id').attr("value", 'val'); 设置隐藏字段值;不能在 IE 中工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13401759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:35:27  来源:igfitidea点击:

Setting hidden field value with Jquery $('#id').attr("value", 'val'); not working in IE

jqueryhidden-field

提问by TrustMe

I noticed that IE doesnt fill the value of a hidden field, using the code below, while Chrome and FF have no problem with this.

我注意到 IE 没有填充隐藏字段的值,使用下面的代码,而 Chrome 和 FF 对此没有问题。

$('#id').attr("value", 'val');

I tried a few other things like .setAttributeor .val() = "val";

我尝试了其他一些事情,例如.setAttribute.val() = "val";

回答by Adil

You need to pass value to val()jquery function,

您需要将值传递给val()jquery 函数,

$('#id').val("your value");