admin管理员组文章数量:1316688
I have a variable in Javascript:
var test ="whatever"
I just want to pass this variable inside a hidden input:
<input type="hidden" class="myinput" value="">
I tried:
$('.myinput').attr('test');
But it does not seem to work.
Thank you for your help.
I have a variable in Javascript:
var test ="whatever"
I just want to pass this variable inside a hidden input:
<input type="hidden" class="myinput" value="">
I tried:
$('.myinput').attr('test');
But it does not seem to work.
Thank you for your help.
Share Improve this question edited Nov 12, 2012 at 22:48 Nat Ritmeyer 5,6788 gold badges48 silver badges59 bronze badges asked Nov 12, 2012 at 22:43 Juliette DupuisJuliette Dupuis 1,0372 gold badges14 silver badges22 bronze badges 1- Did it help, if so please mark it is as accepted for closure. – Selvakumar Arumugam Commented Nov 13, 2012 at 20:00
1 Answer
Reset to default 8- Use
.val
function to set the value of hidden input. - Remove the quotes to consider it as a variable and not a string literal.
See below code:
$('.myinput').val(test);
本文标签: Pass a javascript variable to html jQueryStack Overflow
版权声明:本文标题:Pass a javascript variable to html. jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741999477a2410716.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论