2016-08-02 18 views
0

ich schlinge meinen Code in einer ready Funktion Hilfe benötigen Unten ist mein Code:

var color = "White"; 
$("#btnBlue").hover(function() { color = "Blue" }); 
$("#btnGreen").click(function() { color = "Green" }); 
$("#btnYellow").click(function() { color = "Yellow" }); 
$("table tr td").click(function() { $(this).css("background-color", color); }); 

ich wickeln will der Code in die Funktion unten.

$(document).ready(function() { 

// Your code here. 

}); 

ich schätze jede Hilfe geben kann

+1

Was ist exaclty die Frage? Warum platzieren Sie Ihren Code nicht einfach in der Dokumentbereitschaftsfunktion? – Christos

+1

Was hielt Sie davon ab, es in '$ (document) .ready (function() {' – Rayon

+0

zu verpacken, kopieren Sie einfach Ihren Code auf "// Ihr Code hier." :) – Mehmet

Antwort

0

Sie können dies einfach tun:

$(document).ready(function() { 

var color = "White"; 
$("#btnBlue").hover(function() { color = "Blue" }); 
$("#btnGreen").click(function() { color = "Green" }); 
$("#btnYellow").click(function() { color = "Yellow" }); 
$("table tr td").click(function() { $(this).css("background-color", color); }); 

}); 
+0

Danke ... es funktioniert. –

Verwandte Themen