私は#email divコンテンツを私のjavascriptコードに埋め込もうとしています。jqueryなどを使ってdivコンテンツを(javascriptコード)取得する
例:
<div id="email">[email protected]</div>
私は電子メールアドレスを印刷したいここ
document.write('<img src="' + get_gravatar('Email Here', 150) + '" />');
ありがとうございました!
私は#email divコンテンツを私のjavascriptコードに埋め込もうとしています。jqueryなどを使ってdivコンテンツを(javascriptコード)取得する
例:
<div id="email">[email protected]</div>
私は電子メールアドレスを印刷したいここ
document.write('<img src="' + get_gravatar('Email Here', 150) + '" />');
ありがとうございました!
私はto not use document.writeをお勧めします。
私はjqueryのを使用して、あなたを理解していれば:
(function($) //IIEF format
{
$(function() //wait for doc ready
{
var $img = $('<img></img>'); //create img tag using jquery
var email = $('#email').text().trim() //could also be .html() to get inner html
$img.attr('src', get_gravatar(email, 150)) //add email to src attribute of img tag
$('body').append($img); //change 'body' with whatever you want to add it to; this will append the img tag into the document
}
})(jQuery);
まず、テキストを取得して変数に格納し、それを使用する必要があります。
次を使用することができますのdivメールのJavaScriptで
var email = document.getElementById('email');
document.write('<img src="' + get_gravatar(email, 150) + '" />');
使用.innerHTML
または.textContent
innerHTMLプロパティセットまたはHTMLコンテンツ(インナーHTML)要素の を返します。 。
var emailId = document.getElementById('email').innerHTML;
document.write('<img src="' + get_gravatar(emailId, 150) + '" />');
又は
要素は、文書、文書 タイプ、または表記法である場合はnullを返すのTextContent。文書全体の のテキストとCDATAデータをすべて取得するには、document.documentElement.textContentを使用できます。
var emailId = document.getElementById('email').textContent;
document.write('<img src="' + get_gravatar(emailId, 150) + '" />');
document.write('<img src="' + get_gravatar(document.getElementById("email").innerHTML, 150) + '" />');
jQueryの
希望これは、あなたを助け
var mail = document.getElementById('email').innerHTML;
document.write('<img src="' + get_gravatar(mail, 150) + '" />');
が動作しない:/、[それをしてくださいしてみてくださいここ](http://www.w3schools.com/jquery/tryit.asp?filename=F0O577DN2ZOO) –
これを実行しようとすると、get_gravatar関数の内部からエラーが発生します。http://www.w3schools.com/code/tryit.asp?filename=F0O5N1T083IP –
Omg、うまくいきます! 、非常に私の友人にありがとう:) –