我正在尝试使用命名空间来 chache DOM,但是当我打电话时,我得到“未定义”而不是 jQuery 对象
<form id="create_profile">
<input type="text" name="name"/>
<input type="text" name="email" />
<input type="text" name="password" />
<input type="text" name="passwordconfirm" />
<span onclick="profile.create()">valider</span>
</form>
JS:
var profile = {
create: function(){
alert(profileFields.test); // show done!
alert(profileFields.create_form.attr('id')); // show undefined instead of create_profil
}
}
var profileFields = {
test: "done!",
create_form: $("#create_profile"),
$email: $("input[name='name']", this.create_form),
$password: $("input[name='pass']", this.create_form),
$passwordconfirm: $("input[name='passconfirm']", this.create_form),
$name: $("input[name='email']", this.create_form),
$tel: $("input[name='tel']",this.create_form)
}