동적 양식을 만들고 일부 요소가 필요하며 일부 요소는 필요하지 않습니다. 그리고 나는 그들에게 가치가 있는지 없는지 확인할 수있는 요소를 얻는 방법을 찾으려고 노력했다.JS 요소 클래스를 얻는 방법
$('form').submit(function() {
$('input').each(function(){
isrequired(this.id)
});
});
function isrequired(id){
if (id!=''){
// if (it has the class 'require'){
// return true
// }
// return false
}
}
++++++++++++++++++++++++++++++++++++
$('form').submit(function() {
$('input[type="text"]').each(function(){
if (this.value == $(this).attr('title')){
this.value = '';
}
});
$('input').each(function(){
required = isrequired(this.id)
if (required == true){
alert(this.id + ' ' + required)
}
});
});
function isrequired(id){
if (id!=''){
x = document.getElementById(id)
if(x.className.indexOf("required") > -1){
return true
}else{
return false
}
}
}
는'hasClass'가 매개 변수로 클래스의 이름을 사용
.hasClass
기능을 사용할 수 없습니다 ''. '+ classname'. –@dystroy oops, 나는 그것을 추가하지 않았다. 감사 – brenjt