我有一个函数(如下),当DOM加载时,它会查找每个select输入并添加一个属性
data-prev
跟踪
以前的
在值更改的情况下,所选值为。
$( document ).ready(function() {
//For each select field, add a data-prev attribute set for tracking the previous value for when it gets changed
$('select').each(function(){
$(this).attr("data-prev", $(this).val())
});
}
现在,我的页面包括动态创建的选择字段(在页面加载后),我还需要设置
数据prev
属性所以,我在想,把上面的函数概括成类似
function SetDataPrevAttr(element=None)
if element is None:
for each select field in DOM set the attribute data-prev to its current value
else:
for each select field in the descendant elements of element (including element) set the attribute data-prev to its current value
我该怎么做?