最初のタイプ: button.onclick = function( "alert( 'hello');");
2番目のタイプ: button.onclick = function(){alert( "hello"); };
3番目のタイプ: button.onclick = myAlert;
function myalert(){
アラート( "hello");
}
4番目のタイプ:
この状況はより動的で実用的であり、複数の機能を追加することもできます(追加のイベントの順序は実行の順序です)、ハハ
if(window.addeventlistener){// mozilla、netscape、firefox //element.addeventlistener(Type、listener、usecapture); button.addeventlistener( 'click'、alert('11 ')、false); button.addeventlistener( 'click'、alert('12 ')、false); //実行注文11-> 12} else {// ie button.attachevent( 'onclick'、function(){alert('21 ');}); button.attachevent( 'onclick'、function(){alert('22 ');});実行命令22-> 21}例説明:
button.onclick = function( "alert('31 ');"); button.onclick = function( "alert('32 ');"); button.onclick = function( "alert('33 ');"); //このように記述する場合、最後のメソッドのみがボタンを実行します。 button.attachevent( "onclick"、function(){alert('42 ');}); button.attachevent( "onclick"、function(){alert('43 ');}); //このように記述すると、3つのメソッドがすべて実行されます//もちろん、button.onclick = function( "alert('51 ');"); button.attachevent( "onclick"、function(){alert('52 ');}); //イベントDeTachevent( 'onclick'、func)をリモートで削除します。 // IE FUNC removeEventListener( 'Click'、func)の下で削除イベントfuncを使用します。 // Mozillaの下の削除イベントFUNCを使用し、削除イベントFUNCJSの上記の4つの方法(推奨)OnClickアクションを変更することは、私があなたと共有するすべてのコンテンツです。参照を提供できることを願っています。wulin.comをもっとサポートできることを願っています。