ここにいる人はjQueryを使うように勧めていますが、コードをjQueryに変更して使っ.html()
てみると何もしなかったようなものです。追加する必要のある html コードの半分を削除したこともありました。
単純なタスクでは、ユーザーが onClick イベントを実行する DIV をクリックしたときだけが必要です。
html += "<div onClick='loadnewsstory();' class='news'> this is a test story, for this test story we are not getting data from JSON</div>";
私は両方を試しました
$("#activecontent").html(html);
document.getElementById("activecontent").innerHTML
私が抱えている問題は、次のコードに関連しています。
function newsstories()
{
document.getElementById("activecontent").innerHTML = "<h1 class='newsheader'>Latest News</h1>";
xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST","http://test.com/?uri=loadnews",false);
xmlhttp.send();
var newsreponse = JSON.parse(xmlhttp.responseText);
for (var i = 0, len = newsreponse.length; i < len; ++i) {
var news = newsreponse[i];
if(i % 2 == 0){
cssclass = "even";
}
else
{
cssclass = "odd";
}
// alert(news.featured_image);
document.getElementById("activecontent").innerHTML = document.getElementById("activecontent").innerHTML + "<div class='news " + cssclass + "'><div class='newstitle'><div class='newstitlecolor' id='news_"+ countstory+"'><a href='javascript:loadnewsstory();'>" + news.post_title + "</a></div></div><div class='base' style='background: url('" + news.featured_image + "');'><img src='" + news.featured_image + "' style='width:100%; height:100%;'/></div></div>";
}
}
あなたは私がリンクを持っているこの領域に表示されます
<a href='javascript:loadnewsstory();'>" + news.post_title + "</a>
発火するはずです
function loadnewsstory()
{
navigator.notification.alert(device.uuid);
}
しかし、私はその火をつけていません。
はい、これは iOS および Cordova 用の Web アプリですが、これは JavaScript の問題だと思います。