0

我试图弄清楚单击它时如何将新更改返回或应用回html。

看看“TODO”评论。我可以在 $(o1) 上看到新的值变化,但是如何将它冒泡到具有“this”值的点击调用者?

var fooMouseClick = function(parmThis)
{
    var $HtmlSpans = $(parmThis.parentElement.innerHtml);

    $.each($HtmlSpans, function(i1, o1) {
        if ($(o1).attr('data-column-sort-ordering') == "") {
           $(o1).attr('data-column-sort-ordering', 'ASC');

           //TODO - How to apply this new "$(o1)" changes to parmThis so the parent script caller can be updated.
        }
    });
}
var foo2 = function() 
{
    $('#Box1 li[title="Model"] span.SpanRight-SortOrdering').click(function() {
        fooMouseClick(this);
    });
}
4

2 回答 2

1

该代码$(parmThis.parentElement.innerHtml);创建了一个新对象,因此您所做的每次更改都不会更改原始对象。

试试这个:

var fooMouseClick = function(parmThis)
{
    var $HtmlSpans = $(parmThis).parent().children();

    $.each($HtmlSpans, function(i1, o1) {
        if ($(o1).attr('data-column-sort-ordering') == "") {
           $(o1).attr('data-column-sort-ordering', 'ASC');

        }
    });
}

另请注意,如果您的选择器基于动态更改的值,则应使用委托事件处理程序。例如,如果您想处理具有以下元素的点击事件data-column-sort-ordering="ASC"(此值动态更改),请使用此代码:

$('#Box1').on("click",'li[title="Model"] span[data-column-sort-ordering="ASC"]',function() {
        fooMouseClick(this);
});
于 2013-11-01T14:12:17.697 回答
0

试试这个:

$("#Box1").on("click","li[title='Model'] span.SpanRight-SortOrdering",function() {
    fooMouseClick(this);
});

更多信息在这里。

于 2013-11-01T13:27:01.110 回答