0

私はウェブサイトで作業していて、問題に遭遇しました。私のFAQには、FAQのさまざまな部分にリンクするためのドロップダウンメニューと送信ボタンがあります。これは完全に機能します。送信ボタンは、ページ上の適切なアンカーに動的にリンクするjavascript関数をトリガーします。さらに、ドロップダウンメニューで選択した質問をオレンジ色で強調表示したいと思います。ハイライトが表示されましたが、点滅する前にほんの一瞬だけでした。フラッシュするのではなく、ハイライトを維持する方法を知りたいですか?なぜこれが起こっているのかわかりません。さらに、jQueryを使用してハイライトをフェードインさせるにはどうすればよいですか?divを非表示にしてから.fade()を使用する方法は知っていますが、その結果、すべてのテキストが表示されなくなります。本当にありがとう!

ここにフィドルがあります:http://jsfiddle.net/UjPtv/しかし、送信するとエラーが発生するため、完全には機能しません。これは、この送信が単にJavaScriptを実行しているにもかかわらず、jsfiddleが送信を許可していないためだと思います。回避策をご存知の場合は、リンクを更新できるようにお知らせください。ありがとう!

javascript:

var toggled = 0;
function jump_to (location) {
if(toggled == 0){
    toggled = 1;
    window.location.href = "#" + location;
    $("#wrap"+location).toggleClass("wraps_active");
}
}​

html:

<div id = "main">
        <h2 class = "center">FACTS YOU NEED</h2>
        <h3>The Core Facts You Want To Know</h3>
        <div class = "border">
        <p>
            Jump To: 
              <form onsubmit = "jump_to(jump_list.value)">
              <select name = "jump_list">
              <option value="1">Who can go to the camp?</option>
              <option value="2"><a href = "contact_information.html">When do we check in and out?</a></option>
            </select>
            <input type = "submit" value = "Go"/>
            </form>
        </p>
        </div>
        <div id = "wrap1" class = "wraps">
        <h4><a name = "1"></a>Who can go to the camp? </h4>
        <p>
            The camp is for kids ages 9 to 17 years old who have been diagnosed with celiac disease, a condition that requires life-long adherence to a gluten-free diet.  Given limited space, we are unable to accommodate kids on gluten-free diets for other reasons (such as autism spectrum disorders).  Campers ages 16-17 years may choose to volunteer as junior counselors.  Junior counselors assist the adult volunteers, and for first session junior counselors need to arrive a day early (on Monday) for the staff orientation and training.  If there are more junior counselor applicants than there is available space, priority is given based on age, gender-need, and prior camp experience.
        </p>
        </div>
        <div id = "wrap2" class = "wraps">
        <h4><a name = "2"></a>When do we check in and out?</h4>
        <p>
            Check-in: Please see the "Calendar" on the left hand side of the website for details about each camp.Please do not arrive early.
            </br><br/>
            Check-out:  All campers must be checked out by the stated time so camp can be prepared for the next group, see the "Calendar" for date information.
        </p>
        </div>


    </div>​

css:

.wraps{
border-bottom:1px dashed #C3C3C3;
}
.wraps_active{
border-bottom:1px dashed #C3C3C3;
background:#FFB280;
}​
4

2 に答える 2

4

フォームが送信されるたびに、アクティブなラップクラスをすべてクリーンアップし、選択したクラスにのみ追加します。

$('form input[type=submit]').click(function(e) {
    e.preventDefault();

    var location = $('select[name=jump_list]').val();
    window.location.href = "#" + location;

    $('.wraps').removeClass('wraps_active');
    $("#wrap"+location).addClass("wraps_active");
});

これがフィドルです。

于 2013-01-02T07:22:15.667 に答える
0

これを試してください

 $("#wrap"+location).addClass("wraps_active");

それ以外のtoggleClass

于 2013-01-02T07:10:38.183 に答える