从跨度到输入的值 [英] value from span to input
问题描述
我有span标记中显示的值。如果我想发布值,我必须将该值分配给输入。所以这是我编写的代码,用于为输入赋值并尝试发布该值。但当我提醒指定值时,其
显示为
I have value that is displayed in span tag. If i want to post the value i have to assign that value to an input. So this is the code i have written to assign value to input and trying to post that value. But when i alert the assigned value its showing as
[object Object]
请检查代码并更正我。
var value = $("#spanElement").text();
var lower=$("#inputElement").val(value);
alert(lower);
我也试过这个
var value = $("#spanElement").text();
var lower=$("#inputElement").val(value);
alert(lower);
以上代码均显示
[object Object]
因为这个我无法发布值。
Because of this i am not able to post values.
推荐答案
这是因为输入上的值setter函数只返回该输入元素的jQuery对象,它允许你链接事件。
That is because the value setter function on an input return the jQuery object of that input element only, it allows you to chain the event.
试试这个
var value = $("#spanElement").text();
var lower=$("#inputElement").val(value);
alert(lower.val());
在此处阅读更多相关信息 http://api.jquery.com/val/#val-value
Read more about it here http://api.jquery.com/val/#val-value
这篇关于从跨度到输入的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!