开发者

Is it possible to add a value to a hidden text box field in JQuery

Recently, I came across a web page where someone asked how to add some value to a hidden field.开发者_Go百科

Since I am new to JQuery, I tried using Javascript instead and came up with this code:

<html>
<head>
<script type="text/javascript">
<!--
function t() {
document.testform.testfield.value = "helloworld";
}
-->
</script>
</HEAD>
<body onLoad="t()">
<form name="testform" id="testform">
<input type="hidden" name="testfield" id="testfield">
</form>
</body>
</html> 

The code works only in non-hidden Text Box field.

I am not sure if JQuery can do it.

Is it possible to add a value to a hidden text box field in JQuery?

Please help if you could.


yes ;)

$("input[name=testfield]").attr("value","helloworld");

or

$("#testfield").attr("value","helloworld");

or

$("#testfield").val("helloworld"); //Thx Felix Klinger

and if you wan't to show the form:

$("input[name=testfield]").attr("type","text");

or

$("#testfield").attr("type","text");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜