请编写一个Python函数，该函数可以接受一个字符串和一个整型值作为参数，并返回该字符串中每个单词出现次数最多的前n个单词。如果多个单词的出现次数相同，则按字母顺序排序。


string = 'the quick brown fox jumps over the lazy dog'
n = 3
```python
def top_n_words(string, n):
    word_counts = {}
    words = string.split()
    
    for word in words:
        if word in word_counts:
            word_counts[word] += 1
        else:
            word_counts[word] = 1
    
    sorted_counts = sorted(word_counts.items(), key=lambda x: (-x[1], x[0]))
    
    top_n = [word for word, count in sorted_counts[:n]]
    
    return top_n
```
调用 `top_n_words('the quick brown fox jumps over the lazy dog', 3)` 将返回 `['the', 'jumps', 'over']`。