###前提・実現したいこと
ここに質問したいことを詳細に書いてください
下記のコードでaタクをクリックした時、morebtクラスのidを取得し、locationでurlにパラメータを追加→
if文でパラメータがあることを確認されたら、下記のコードのよう、htmlを書き換える動きを実装したいのですが、
なぜかパラメータが追加された後に、htmlが元の状態に戻ってしまいます…
コードの実行順の問題かとも思い、
先にhtmlを書き換え、パラメータを追加する方法や
その逆の方法も試したのですが、どちらもhtmlが元に戻るだけでした…
一瞬だけhtmlが変わることからコード自体は順番通り実行されているようですが、
なぜか最後に元の状態に戻ってしまいます…
《参考サイト》
http://imas-cinderella.com/news/
http://www.hai-furi.com/news/
のように、各記事をクリックしたらurlの後ろにパラメータを付けたいのですが
これがなかなか上手くいきません…
お手数ですが、ご回答の程、
何卒宜しくお願い致します。
###発生している問題・エラーメッセージ
エラーメッセージは出ていませんが、urlにパラメータを与えた後、一瞬下記のコード通りにhtmlが変わりますが、 また最初のhtmlの状態に戻ってしまいます…
###該当のソースコード
$(document).ready( function(){ $("a.morebt").click(function(e){ e.preventDefault(); var id = $(this).attr("id"); var url = location.href; var pair=document.location.search; window.location.search = '?article_id=' + id; if( pair.length !== null ){ var html = ""; var category = $(this).parent().parent().parent().find(".news_category").text(); var title = $(this).parent().parent().parent().find(".news_title_text").text(); var texts = $(this).parent().parent().parent().find(".news_text").text(); var imgArray = []; var thumb = $(this).parent().parent().parent().find(".news_thumb img").each(function(){ text = $(this).attr("src"); imgArray.push(text)}); $("#allwrap").addClass("detail"); $(".news_box").css({"display": "none"}); html += '<div class ="news__detail_box mode_detail">'; html += '<div class="news__detail_title cf">'; html += '<div class="news__detail_category"><p>' + category + '</p></div>'; html += '<div class="news__detail_title_text"><p>' + title + '</p></div>'; html += '</div>'; html += '<div class="news__detail_thumb">'; html += '<img src="' + imgArray[0] + '">'; html += '</div>'; html += '<div class="news__detail_text"><p>' + texts + '</p></div>'; html += '<div class="news__detail_share">'; html += '</div>'; html += '<div class="news__detail_nav">'; html += '</div>'; html += '</div>'; $("#news").html(html); } }); });
###試したこと
上記で述べたよう、コードの読み込み順番を変えるなどは
試してみましたがダメでした…
###補足情報(言語/FW/ツール等のバージョンなど)
html / css / javascript / jquery dw cs6

回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。