2015-05-21 33 views
0

我想將一些內聯代碼移入一個函數。從Onclick內聯功能代碼問題

這個工程:

<img onclick="window.plugins.socialsharing.share('Mesasage: ' + $('#divA').html() +' - '+$('#divB').html()+' cars - '+$('#males_count_pecentage').html()+' bikes', 'subject here', 'http://mysite/image.png', 'http://abc.go.com')" src="images/share_text.png" style="height:2em" /> 

但是,當我這樣做:

function myfunc() { 

    alert('hello'); 
    window.plugins.socialsharing.share('Mesasage: ' + $('#divA').html() +' - '+$('#divB').html()+' cars - '+$('#males_count_pecentage').html()+' bikes', 'subject here', 'http://mysite/image.png', 'http://abc.go.com'); 

} 

,這稱之爲從功能:

<img onclick="myfunc();" src="images/share_text.png" style="height:2em" /> 

什麼也沒有發生。

我在這裏忘記了什麼嗎?

+0

你有沒有檢查錯誤控制檯? –

+0

是的,沒有錯誤 – Satch3000

+0

你有警報? –

回答

1

嗨,我只是在瀏覽器中測試它。它似乎工作。也許你已經包含了函數false。我只是在這篇文章中寫了一段簡短的代碼聲明。隨時嘗試一下吧!

<script> 
 
function myfunc() { 
 

 
    alert('hello'); 
 
    window.plugins.socialsharing.share('Mesasage: ' + $('#divA').html() +' - '+$('#divB').html()+' cars - '+$('#males_count_pecentage').html()+' bikes', 'subject here', 'http://mysite/image.png', 'http://abc.go.com'); 
 
} 
 
</script> 
 
<img onclick="myfunc();" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSWtE_a5B3SFO386Eq9H0g5GklQUrwkXo64UsiLKgsGvFQZe937" style="height:2em" />