将 jquery 变量分配给输入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12949041/
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:08:56  来源:igfitidea点击:

assign jquery variable to input

jquery

提问by user1710288

I am trying to pass jquery variable value to input text. I tried the below and getting message "The left-hand side of an assignment must be a variable". How to send jquery variable value to input box?

我正在尝试将 jquery 变量值传递给输入文本。我尝试了下面的操作并收到消息“赋值的左侧必须是变量”。如何将jquery变量值发送到输入框?

//Input is as below

//输入如下

<input  type="hidden" id="rowValues" value="" name="rowValues">

//jquery is as below. rowData variable value should be passed to input

//jquery如下。rowData 变量值应传递给输入

 var rowData = JSON.stringify(rows); ; 

$("#rowValues").val() = rowData; 

回答by Sudhir Bastakoti

do:

做:

$("#rowValues").val(rowData);

回答by codingbiz

You use $("#rowValues").val()when you want to get data from

您可以使用$("#rowValues").val(),当你想从数据

 var data = $("#rowValues").val();

But for assigning data to input

但是为了将数据分配给输入

 $("#rowValues").val(data);

回答by Christophe

var rowData = JSON.stringify(rows);
$("#rowValues").val(rowData);  

回答by Saifuddin Sarker

try this:

尝试这个:

 $("#rowValues").val(rowData); 

回答by Musa

To set the value you pass the parameter to the .val()function.

要设置值,您将参数传递给.val()函数。

$("#rowValues").val(rowData); 

回答by Talha

should be

应该

$("#rowValues").val(rowData);