Javascript 从jquery对话框还原原始数据,脚本不工作
我正在jQuery中创建一个对话框,并使用下面的建议清除点击cancel按钮时的数据Javascript 从jquery对话框还原原始数据,脚本不工作,javascript,jquery,html,jquery-ui,jquery-ui-dialog,Javascript,Jquery,Html,Jquery Ui,Jquery Ui Dialog,我正在jQuery中创建一个对话框,并使用下面的建议清除点击cancel按钮时的数据 // store the old content var myOldContent = $("#cancelbutton").html(); // change content $("#cancelbutton").html(someNewContent); // and change it back $("#cancelbutton").html(myOldContent); 问题是这个方法会清除数据,
// store the old content
var myOldContent = $("#cancelbutton").html();
// change content
$("#cancelbutton").html(someNewContent);
// and change it back
$("#cancelbutton").html(myOldContent);
问题是这个方法会清除数据,但我使用的两个输入在清除信息后不起作用
我有一个日历输入(调用external.js)和一个colorPicker,也在external.js中初始化
如何在不丢失这两个组件功能的情况下清除数据?不要使用只接受html本身而不是包含事件侦听器和数据的实际DOM对象的.html()
我的建议是这样做,尽管根据您的布局可以采用很多不同的方式:
// store the old content
var myOldContent = $("#cancelbutton").clone(true); // 'true' so events are copied
// change content
$("#cancelbutton").html(someNewContent);
// bind new events for the newContent here
// and change it back
$("#cancelbutton").replaceWith(myOldContent);
在这两个输入上是否有一些事件侦听器?日历使用jQuery中的datepicker ui,而colorpicker具有捕获事件的事件侦听器:selectorParent=$(event.target).parents(“#”+selector.attr('id')).length;如果(event.target==$(选择器)[0]| | event.target===selectorOwner[0]| | selectorParent>0){return;}$.fn.colorPicker.hidePalette();日历使用输入上选择的值(日期从-日期到)初始化,并具有beforeShow函数调用..等等,您是指输入标记吗?在这种情况下,只需执行
$(“input”).val(“”
)即可将其清除。