2011-09-17 25 views
0

我有一個創建的jQueryUI排序和排序後,我想用其他整數替換此代碼塊中的所有整數,除了在textarea,輸入和其他表單值的整數。這是我的:在代碼中替換整數除了公式值

$('.sortable').sortable({ 
    stop: function(event, ui) { 
     ui.item.parent().find('li').each(function(index) { 
      var new_html = $(this).html().replace(/\d+/g, (index + 1)).replace(/\d+/, (index + 2)); 
      $(this).html(new_html); 
     }); 
    } 
}); 

非常感謝幫助。最好的問候,.wired

+0

如表單元素也可以輸入HTML,我認爲正則表達式是不是防彈夠的工作,所以我必須首先排除值,更換整數,然後將零件粘在一起。 –

回答

0

聽起來像是.not()

var tagsToReplace = $(this).children().not("input, textarea"); 
tagsToReplace.each(function(index) { 
    $(this).html() = $(this).html().replace(/\d+/g, (index + 1)).replace(/\d+/, (index + 2)); 
}