使用JQuery设置隐藏字段的值 [英] Set the Value of a Hidden field using JQuery

查看:153
本文介绍了使用JQuery设置隐藏字段的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用JQuery设置隐藏字段的值。

I want to set the value of a hidden field, using JQuery.

隐藏字段:

<input id="chag_sort" type="hidden" name="chag_sort">

我的JQuery:

 $("#input[name=chag_sort]").val(sort2);

我做错了什么?我还应该在控制台中提到sort2确实有一个值:DESC。

What am I doing wrong? I should also mention in console that sort2 does in fact have a value: DESC.

推荐答案

选择器不应该是 #INPUT 。这意味着一个 id =input的字段,这不是你的情况。你想要:

The selector should not be #input. That means a field with id="input" which is not your case. You want:

$('#chag_sort').val(sort2);

或者如果您的隐藏输入没有唯一ID但只有 name =chag_sort

Or if your hidden input didn't have an unique id but only a name="chag_sort":

$('input[name="chag_sort"]').val(sort2);

这篇关于使用JQuery设置隐藏字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆