Tuesday, 15 May 2012

javascript - JQuery .html can not adding variable value into a href -



javascript - JQuery .html can not adding variable value into a href -

i want create list of news on webpage. when mouse click on content, there url available. illustration apple news

here sample codes, problem is: when seek add together variable's value href, href="www.search.com?keyword="+var.keyword, display apple news

actually there 50 objects in variable model, having 50 model.link , model.keywords, please help me alter sample code works on w3cshools.com "try youself". tried 10 times don't know how prepare it, thanks!

<!doctype html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> <!-- should end tag--> var model=[{"link":"http://www.google.com?keyword=","keyword":"apple" "content":"this news"}] <!-- miss ";" @ end of line --> </script> <script> $(document).ready(function(){ $("p").html("click <a href=model.link+model.keyword>this link</a>"); <!--finally works: $("p").html("click <a href='"+model[0].link+model[0].keyword+"'>this link</a>");--> }); </script> </head> <body> <p>a content</p> </body> </html>

quote properly:

$("p").html("click <a href="+model.link+model.keyword+">this link</a>");

javascript jquery html json

No comments:

Post a Comment