基本上我有几个div,每个包含一个问题。这个问题可以用单个输入,单选按钮或复选框来呈现。如何识别儿童输入类型
我想确定输入类型是什么,当通过div循环。
下面的代码实现这个不起作用,只是试图展示我想要实现的。
$(".question").each(function(){
var type = $(this).children('input').attr("type").val();
alert(type);
});
基本上我有几个div,每个包含一个问题。这个问题可以用单个输入,单选按钮或复选框来呈现。如何识别儿童输入类型
我想确定输入类型是什么,当通过div循环。
下面的代码实现这个不起作用,只是试图展示我想要实现的。
$(".question").each(function(){
var type = $(this).children('input').attr("type").val();
alert(type);
});
卸下VAL():
var type = $(this).children('input').attr("type");
例如
$(document).ready(function(){
$('button').click(function(){$(".question").each(function(){
var type = $(this).children('input').attr("type");
alert(type);
});
});
});
<div class="question">
<input type="radio">hello</input>
</div>
<div class="question">
<input type="checkbox">hello</input>
</div>
<div class="question">
<input type='text' name='response[4][answer]'></input>
</div>
<button>Click</button>
这应该让你去:
$('div').each(function(){
$(this).children('input').each(function(){
alert($(this).attr('type'));
});
});
var type = $(this).find("input").get(0).type;
感谢这个工程,即使输入是在儿童的内部 – Geomorillo 2013-09-12 14:15:24
定义 “不工作” 它抛出一个错误?它做什么? 我不认为你需要.val()的attr – Patricia 2011-05-27 14:04:15
以及没有什么。我假设,因为我没有办法缩小到一个特定的输入 – buymypies 2011-05-27 14:06:40