- //Place this plugin snippet into another file in your applicationb
- (function ($) {
- $.toggleShowPassword = function (options) {
- var settings = $.extend({
- field: "#password",
- control: "#toggle_show_password",
- }, options);
- var control = $(settings.control);
- var field = $(settings.field)
- control.bind('click', function () {
- if (control.is(':checked')) {
- field.attr('type', 'text');
- } else {
- field.attr('type', 'password');
- }
- })
- };
- }(jQuery));
- //Here how to call above plugin from everywhere in your application document body
- $.toggleShowPassword({
- field: '#test1',
- control: '#test2'
- });
html
- Password:
- <input type="password" id="test1" value="a" />
- <input id="test2" type="checkbox" />Show password
转载请注明:谷谷点程序 » jquery显示隐藏密码文本框