0
获取ID,我有以下形式从serializeArray
<form action="test.php" id="loginform" name="loginform" method="post">
<input name="title[]" id="title1" type="text" value="" tabindex="1" />
<input name="title[]" id="title2" type="text" value="" tabindex="2" />
<input name="title[]" id="title3" type="text" value="" tabindex="3" />
<input type="submit" name="submit" value="Submit" id="submit" tabindex="4" />
</form>
我能够获得元素的名称,但使用此代码不是它的ID。
$('#loginform').bind('submit', function() {
var elements = $(this).serializeArray();
$.each(elements, function(i, element) {
var temp = $('#' + element['name']);
var name = this.name; alert(name);
var id = this.id; alert(id); ///even id = this.attr("id"); not getting
var value = this.value;
(temp.val() == '') ? temp.css({'background': '#FFC4C4', 'border': '1px solid #F00'}) : temp.removeClass('hightlight');
});
return false;
});
尝试了所有的可能性,但它说undefined var id = this.id; alert(id); var id = this.attr(“id”); alert(id); – 2011-01-27 09:42:34