使用javascript设置隐藏的输入值 [英] Set hidden input value with javascript

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

问题描述

function GetWidth(){
    var TBL_width = document.getElementById('wrap_tbl').offsetWidth;
    return TBL_width;
}
var w = GetWidth();

<input type="hidden" id="tbl" value= w />

这可能吗?

我想将JavaScript变量存储在隐藏的输入元素的value属性中.请指导我如何做

I want to store a JavaScript variable in value attribute of a hidden input element. Please guide me how to do this

推荐答案

Jquery版本:

$("#tbl").val(w);

JavaScript版本:

document.getElementById("tbl").value = w;

在这种情况下,隐藏和未隐藏"输入之间没有区别.

There is no difference between hidden and "unhidden" inputs in this case.

建议:如果您的GetWidth函数只有一行,并且该行不太复杂,则可以从方法中将其提取.

Advice: If your's GetWidth function has only one line, and the line isn't too much sophisticated, you can extract it from the method.

function setWidth(){
    var TBL_width = document.getElementById('wrap_tbl').offsetWidth;
    document.getElementById("tbl").value = TBL_width;
}

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

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