Javascript使用name属性选择表单元素 [英] Javascript selecting form elements using name attribute
本文介绍了Javascript使用name属性选择表单元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用它的名称属性来选择表单元素?
例如,如果我有这样的事情:
< input type =textname =my_element/>
我会如何设置一个javascript变量到这个输入的值?
var name_val = $(input [name ='my_element'])。val();
?
解决方案 (')。val()你几乎在那里
var name_val = $ ;
Is it possible to select a form element using it's name attribute?
For example if I had something like this:
<input type="text" name="my_element" />
How would I go about setting a javascript variable to the value of this input?
var name_val = $(input[name='my_element']).val();
?
解决方案
Your almost there
var name_val = $('input[name=my_element]').val();
这篇关于Javascript使用name属性选择表单元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文