为什么我的 HTML 替换分配不起作用?

Why is my HTML replacement assignation not working?

选择后,我想用其他内容替换当前内容。当从下拉列表中选择 "Tom Sawyer" 时,我正在尝试替换(目前)从先前选择到 "Tom Sawyer will be added later" 的更改。但它不起作用 - 现有的 HTML (HuckFinn) 仍保留在 div 中。这是相关代码:

$('#fictionDropDown').change(function () {
    configLoading();
    var sel = this.value;
    if ((sel == "HuckFinn") && (currentFictionSelection != "HuckFinn")) {
        $('#FictionContent').load('Content/HuckFinn.html');
        currentFictionSelection = "HuckFinn";
    }
    else if ((sel == "TomSawyer") && (currentFictionSelection != "TomSawyer")) {
        $("#FictionContent").empty();
        $('#FictionContent').html('Tom Sawyer will be added later');
        currentFictionSelection = "TomSawyer";
    }

...和HTML:

<div id="tabs" class="content-wrapper">
    <ul>
        <li><a href="#tab-Fiction">Fiction</a></li>
        <li><a href="#tab-Nonfiction">Nonfiction</a></li>
        <li><a href="#tab-MiscTwain">Miscellaneous</a></li>
        <li><a href="#tab-Media">Media</a></li>
    </ul>
    <div id="tab-Fiction">
        <select id="fictionDropDown">
            <option value="HuckFinn">Huck Finn</option>
            <option value="TomSawyer">Tom Sawyer</option>
            <option value="tPatP">Prince and the Pauper</option>
            <option value="ConnYank">Connecticut Yankee</option>
            <option value="Gilded">The Gilded Age</option>
            <option value="Puddnhead">Pudd'nhead Wilson</option>
            <option value="ShortStories">Short Stories</option>
        </select>
        <div id="FictionContent" class="clearfix">Content in Fiction tab</div>
    </div>

如果有调试此代码的方法,将会有所帮助。我在代码中设置了断点,但是 none 被命中了。

无论如何,为什么清空 html 然后将其设置为 "Tom Sawyer will be added later" 不起作用?

用一个值初始化 currentFictionSelection,现在一切正常:

var currentFictionSelection = 'somevalue';

$('#fictionDropDown').change(function () {
    //configLoading();
    var sel = this.value;
    if ((sel == "HuckFinn") && (currentFictionSelection != "HuckFinn")) {
        alert('foo');
        $('#FictionContent').load('Content/HuckFinn.html');
        currentFictionSelection = "HuckFinn";
    } else if ((sel == "TomSawyer") && (currentFictionSelection != "TomSawyer")) {
        alert('bar');
        $("#FictionContent").empty();
        $('#FictionContent').html('Tom Sawyer will be added later');
        currentFictionSelection = "TomSawyer";
    }
});

演示:http://jsfiddle.net/BenjaminRay/u8rz59Lm/