2013-05-14 63 views
0

我试图在点击时更新表格中某个字段的HTML。当它被点击时,一个类被应用并且在'headerSortUp'和'headerSortDown'之间交替。点击切换时更新元素的HTML

这是我到目前为止有:

$(document).on('click', "table#archive-table thead tr th.headerSortUp", function(){ 
    $(this).html('Date <span class="ss-icon ss-gizmo">up</span>'); 
}); 

我还需要补充,所以如果类是“headerSortDpwn”是更新HTML到Date <span class="ss-icon ss-gizmo">down</span>

让我知道如果你能帮助或如果我没有说清楚。

感谢, [R

UPDATE

http://jsfiddle.net/Rx9pD/1/

回答

0

试试这个:

$('#archive-table ').on('click', "th", function() { 
    if ($(this).hasClass('headerSortUp')) $(this).html('Date <span class="ss-icon ss-gizmo">up</span>'); 
    else if ($(this).hasClass('headerSortDown')) $(this).html('Date <span class="ss-icon ss-gizmo">down</span>'); 
}); 
+0

感谢您的帮助。我觉得这应该工作,但它不更新HTML ... – 2013-05-14 10:32:09

+0

@rdck:发布一个功能的例子,说明你的问题http://jsfiddle.net/然后我可以看看这个问题。 – 2013-05-14 12:27:05

+0

非常感谢 - http://jsfiddle.net/Rx9pD/1/ – 2013-05-14 15:47:47

0
$("table#archive-table thead tr th").click(function (e) { 

    if ($(this).hasClass("headerSortUp")){ 
     $(this).removeClass("headerSortUp"); 
     $(this).addClass("headerSortDown"); 
    } 
    else{ 
     $(this).removeClass("headerSortDown"); 
     $(this).addClass("headerSortUp"); 
     S(this).html('Date <span class="ss-icon ss-gizmo">down</span>'); 
    } 
}); 

在html()函数把,而不是整个完整的HTML是什么你在你的问题中提供。我还假设headerSortUp类最初应用于您的th单元格。