在WordPress菜单中,我需要在父级<li>
有3级时(当父级的子菜单也有子菜单时)将其添加到父级<ul>
<li>Parent
<ul class="sub-menu">
<li>Sublink1</li>
<li>Sublink2</li>
</ul>
</li>
<li>Parent</li>
<li class="mega">Parent <!-- add class here b/c it has 3 levels -->
<ul class="sub-menu">
<li>Sublink1</li>
<li>Sublink2</li>
<li>Sublink3
<ul class="sub-menu">
<li>Sublink1</li>
<li>Sublink2</li>
</ul>
</li>
</ul>
</li>
<li>Parent</li>
<li>Parent</li>
<li>Parent
<ul class="sub-menu">
<li>Sublink1</li>
<li>Sublink2</li>
</ul>
</li>
</ul>
。换句话说:
//store the last visited row
var row = false;
// save the row if has changed
function save () {
if (row.changed){
console.log("save");
}
}
// keep track of the row you are in
// it doesnt work when you leave the table
$("tr").on("focusin", function (e) {
if (row != this){
if (row){
save();
}
row = this;
e.stopPropagation();
}
});
//keep track whenever the row changes
$("tr").on("change", function (e) {
this.changed = true;
console.log("changed");
})
//triggers when you leave the table, you can try to save changes then.
$(document).on("focusin", function (e) {
var el = $(e.target); //input or element that triggers this event
var elrow = el.parent().parent()[0]; // try to get the row from that input, ... if its an input
if (row && row !=elrow) {
save();
e.stopPropagation();
};
})
我确定我需要使用Walker来实现这一目标,但我无法找到一个像这样做的例子。谢谢!