라디오 버튼 값이 변경된 경우에만 제출 버튼을 표시하려고합니다. 라디오 그룹이 여러 개있을 것이며 라디오 버튼이 변경되면 버튼이 나타납니다! 또한 라디오 버튼 그룹 값이 기본값으로 설정되면 제출 버튼이 다시 숨겨집니다.변경 라디오 버튼 상태 표시 제출 버튼 ... 어떻게?
$("form :radio").live('change',function(){
});
내 새로운 코드 :
//hide the submit button on load
$('form :submit').hide();
//Data structure where the initial value from radio button(s) will be stored
var dbRadios = [];
//Getting the initial values from the radio button(s) and load them to the data structure
$("form :radio:checked").each(function() {
dbRadios.push($(this).attr('value'));
});
//Attach onclick event to radio button(s)
$('form :radio').click(function() {
//The event fired, therefore the "New value(s)" (radio button value(s)) will be stored in the data sctructure
var submitedRadios = [];
//Geting the values from checked radio buttons
$("form :radio:checked").each(function() {
submitedRadios.push($(this).attr('value'));
});
//Now comparing both data structures
if(dbRadios.compare(submitedRadios)){
$('form :submit').fadeOut('slow');
}else{
$('form :submit').fadeIn('slow', function(){ ACTION! WILL BE EXECUTED MANY TIMES AS BUTTONS CLICKED});
}
});
$("form").submit(function() {
//AJAX GOES HERE!
alert("a submeter dados");
})
비교 기능 :
//Compare two different arrays
Array.prototype.compare = function(testArr) {
if (this.length != testArr.length) return false;
for (var i = 0; i < testArr.length; i++) {
if (this[i].compare) {
if (!this[i].compare(testArr[i])) return false;
}
if (this[i] !== testArr[i]) return false;
}
return true;
}
어떻게 만들어 졌습니까? 간단한 예를 들어 주시겠습니까? – obinoob
WarFox의 코드는이 코드가 아마도 예제 – Ascherer
에 대해 "대답"했습니다. 내 대답에 누군가가 더 완전한 버전을 가지고 있다고 대답했는데, 어떻게 대답하지 않았는지 확실하지 않습니다. – Ascherer