간단한form 폼 조작의 몇 가지 쓰기

2167 단어
function save(){
	var name = $('#name').val();
	var email = $('#email').val();
	
	//...
}

function setValue(name,email){
	$('#name').val(name);
	$('#email').val(email);
}

//=============================================

function save(){
	var user = {};
	user.name = $('#name').val();
	user.email = $('#email').val();
	
}

function setValue(user){
	$('#name').val(user.name);
	$('#email').val(user.email);
}

//=============================================

var user = {};
user.dom = '#userform';
user.save = function(){
	this.name = $(this.dom).find('input[name="name"]').val();
	this.email = $(this.dom).find('input[name="email"]').val();
}
user.setValue = function(user){
	this.name = user.name;
	this.email = user.email;
	$(this.dom).find('input[name="name"]').val(this.name);
	$(this.dom).find('input[name="email"]').val(this.email);
}

//=============================================

function user(opts){
	this.dom = opts.dom;
}
user.prototype.save = function(){
	this.name = $(this.dom).find('input[name="name"]').val();
	this.email = $(this.dom).find('input[name="email"]').val();
}
user.prototype.setValue = function(user){
	this.name = user.name;
	this.email = user.email;
	$(this.dom).find('input[name="name"]').val(this.name);
	$(this.dom).find('input[name="email"]').val(this.email);
}

//=============================================

function user(opts){
	this.dom = opts.dom;
	this.name = opts.name;
	this.email = opts.email;
}
user.prototype.getValue = function(){
	this.name = this.nameDom.val();
	this.email = this.emailDom.val();
}
user.prototype.setValue = function(user){
	this.name = user.name;
	this.email = user.email;
	this.nameDom.val(this.name);
	this.emailDom.val(this.email);
}
user.prototype.save = function(){
	//$.post...
}
user.prototype.bindDom = function(){
	this.nameDom = $(this.dom).find('input[name="name"]');
	this.emailDom = $(this.dom).find('input[name="email"]');
}

좋은 웹페이지 즐겨찾기