2017-01-20 4 views
0

私にはjQuery関数を書く関数がありますが、そのjQuery(クリックイベント)を実行する時間が来たら、コードは決してdocument.readyになっているようです「冒頭に」存在しなかった。どのように私はそれが関数によって作成された後、コードを "準備"できますか?準備が整ったjQueryを関数で作成した後

function readyclick(array){ 
    $("script").append("$(document).ready(function({ 
     $('#"+array+"').on('click', function(){$('#"+array+"').hide(); 
    } 
} 

答えて

0

あなたのコードがドキュメントの準備ができて正しく実行されるように、次のように記述する必要があります。

$(function(){ 
//what evenr written inside this code will get executed on document ready 

    // it seems you need to add some event. Usually events are added to HTML 
    // controls and can be easily identified with help of ID or Name or Class 
    // ++array++ does't seems name or id of any element. so check which html you 
    //want to bind your event with. 
    // if it is a class write ".CLASS_NAME" if it is ID write "#Element ID" 
    $("Your_element_selector").click(function(){ 
    /what ever you write inside this function will executed on click event of this element 
    $(this).hide(); // you can access element using $(this); 
    }); 

}); 
+0

あなたは正しいです!私は "#"を忘れていた。しかし、それをクリックしてもまだ実行されません... – CamdyCorn

0

私はあなたの「readyclick」機能の実行が完了した後、あなたは、単にこれは準備ができてコールバックであるjQueryのコードを実行するの世話をする必要があります

$.ready(); 

を行うことができると思います。

+0

だから私はそれを試しています、そしておそらく私はそれを間違って配置していますか?これはどこに行くの? – CamdyCorn

関連する問題