我有以下表格
<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;
});