1.获取被选元素的属性值。
$(selector).attr(attribute)
其中attribute为属性名,什么属性都可以,一般常用class,id,如自己定义的属性也可以
<html>
<a id="test" yan="ILU">aaa</a>
</html>
<script>
alert($("#test").attr("yan");
</script>
也会打出“ILU”的。这个真的挺棒棒的,之前没有体会到这个attr的具体含义,深入测试了一下用起来还是挺方便的,不然只有id和class可以用还是挺难受的。
2.刷新页面
window.location.reload();
3.a标签通过href实现页面跳转
<a href="pwdManagement.html" target="_self">修改</a>
target 属性规定在何处打开链接,默认"_self":在相同页面中打开,"_blank":在新窗口中打开。
4.select点击变化时需要绑定on'change'方法,因为需要实时改变
//根据select选择变化
$("#checkselectPho").on('change',function () {
var type = $(this).prop('selectedIndex');
var param= $.extend({},param);
$.when(userser.userinfo(param)).done(
function (resp) {
console.log(typeof type,resp.userInfoMap);
if (type === 0) {
$("#checkTypePho").html("原手机");
$("#checkValPho").html(resp.userInfoMap.PHONE);
} else if (type === 1) {
$("#checkTypePho").html("原邮箱");
$("#checkValPho").html(resp.userInfoMap.EMAIL);
}
})
})
但根据类型判断点击“获取验证码”调用的函数时不需要绑定on'change',因为此时的select的index已经固定了。
//修改手机时根据不同类型获取验证码
ret.getCodePho = function (param) {
var checkType = $("#checkselectPho").val();
if(checkType == "phone"){
sendMessage($("#checkValPho").html(), $(".getVcodePho").attr("id"));
}else if(checkType == "email"){
sendEmail($("#checkValPho").html(), $(".getVcodePho").attr("id"));
}
}