【发布时间】:2021-03-06 02:48:08
【问题描述】:
我不相信任何类似的现有问题可以回答这个问题。
我正在开发一个插件,可以将<input type='checkbox' /> 转换为具有两个切换状态的<div>。使用的基本思路是:
$('div .checkboxContainer').prettyBox();
插件本身的伪代码是:
$.fn.prettyBox = function(){
return this.each(function(){
$(this).find(':checkbox').each(function(){
.. grab all event handlers on the current <input>
.. create a new <div>
.. attach all of the <input>'s event handlers to the <div>
.. hide the <input>
.. place the <div> where the <input> used to live
});
};
};
其他提出类似问题的人一直关注复制单个事件,例如 click 处理程序。为了保持插件的灵活性,我认为我的代码循环遍历输入的所有内容并将其复制过来是很重要的。
【问题讨论】:
标签: jquery jquery-events dom-manipulation