简体   繁体   English

如何将JavaScript值连接到HTML输入“名称”字段?

[英]How To Concatenate JavaScript Value to HTML Input 'name' Field?

I have one variable value in my jQuery ready function, and I have one HTML input tag. 我有一个变量value在我的jQuery就绪功能,我有一个HTML输入标记。 I want this variable to be concatenated to input tag name field. 我希望将此变量连接到输入标签名称字段。 Please help me. 请帮我。

Are you using jQuery ? 您正在使用jQuery吗?

You can use $.prop("id") if you are. 您可以使用$ .prop(“ id”)

supposing value is the value you need to add 假设value是您需要添加的值

$('selector').attr('name', $('selector').attr('name') + value);

this will do 这会做

Since you are using jQuery, try $.attr() 由于您使用的是jQuery,请尝试$ .attr()

var myName = 'abc';
var $el = $('input[name=xyz]');

$el.attr('name', $el.attr('name') + myName);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM