var flag = 0; var pwdxs = $("#pwdxs"); var iconposition = $("#iconposition"); $(".icon-position").click(function () { if(flag==0){ pwdxs.prop("type","text"); iconposition.html('<use xlink:href="#icon-xianshi"></use>'); flag=1; }else{ pwdxs.prop("type","password"); iconposition.html('<use xlink:href="#icon-wuxingde2"></use>'); flag=0; } })