2016-11-11 10 views

答えて

1

私は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); 
+0

が動作しない:/、[それをしてくださいしてみてくださいここ](http://www.w3schools.com/jquery/tryit.asp?filename=F0O577DN2ZOO) –

+0

これを実行しようとすると、get_gravatar関数の内部からエラーが発生します。http://www.w3schools.com/code/tryit.asp?filename=F0O5N1T083IP –

+0

Omg、うまくいきます! 、非常に私の友人にありがとう:) –

0

まず、テキストを取得して変数に格納し、それを使用する必要があります。

次を使用することができますのdivメールのJavaScriptで

var email = document.getElementById('email'); 
document.write('<img src="' + get_gravatar(email, 150) + '" />'); 
0

使用.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) + '" />'); 
0
document.write('<img src="' + get_gravatar(document.getElementById("email").innerHTML, 150) + '" />'); 

jQueryの

​​
0

希望これは、あなたを助け

var mail = document.getElementById('email').innerHTML; 
document.write('<img src="' + get_gravatar(mail, 150) + '" />'); 
関連する問題