问题描述
如何获取 input
元素的 id 或 name code> type =text来自动态生成的HTML。
我需要获取 < input name =ctl00 $ DefaultContent $ ctl2type =text>
< TR>
< td class =TextBold> 1.< / td>
< td class =TextBold>问题1的内容:< / td>
< td class =TextBold>
< input name =ctl00 $ DefaultContent $ ctl2type =textclass =TextNormal/>
< / td>
< / tr>
预先感谢
BB p>
Descriptiom
您<输入名称=ctl00 $ DefaultContent $ ctl2type =textclass =TextNormal/>
没有 id
属性。但是,您可以使用此选择器获取每个输入类型文本
的集合 $(input [type ='text'])
。我想你想得到 name
属性。
查看示例和。
样本
$(function(){
$(input [type ='text'])。each(function(){
alert(id =+ $(this).attr(id));
alert(name =+ $(this).attr(name));
}) ;
});
更多信息
'UL>
更新
您的输入
元素有一个类
属性。您可以使用
$( class>
(id =+ $(this).attr(id));
alert(name =+ $(this).TextNormal)。 .attr(name));
});
How can I get the id or name of input
element of type="text"
from dynamically generated HTML.
I need to get the Id of <input name="ctl00$DefaultContent$ctl2" type="text">
<tr>
<td class="TextBold" >1.</td>
<td class="TextBold" >Content for Question 1:</td>
<td class="TextBold" >
<input name="ctl00$DefaultContent$ctl2" type="text" class="TextNormal" />
</td>
</tr>
Thank in advance
BB
Descriptiom
Your <input name="ctl00$DefaultContent$ctl2" type="text" class="TextNormal" />
has no id
attribute. But you can get a collection of every input type text
using this selector $("input[type='text'])
. I think you want to get the name
attribute.
Check out the sample and this jsFiddle Demonstration.
Sample
$(function() {
$("input[type='text']").each(function() {
alert("id = " + $(this).attr("id"));
alert("name = " + $(this).attr("name"));
});
});
More Information
Update
Your input
element has a class
attribute. You can get all elements that has this class
using
$(".TextNormal").each(function() {
alert("id = " + $(this).attr("id"));
alert("name = " + $(this).attr("name"));
});
这篇关于从动态生成的HTML JQuery获取元素的Id /名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!