Voici un code fonctionnel et fonctionnel. Lorsque je copie le coller dans un fichier texte testFile.html
puis l'ouvrir avec un navigateur, cela fonctionne très bien.Comment exécuter une fonction js onload?
Mais je veux la fonction selectCollege
à exécuter juste après la fonction initViz
J'ai essayé
<body onload="initViz();selectCollege('Engineering');"> . . .
Mais cela n'a pas fonctionné. Comment puis-je exécuter la fonction selectCollege
juste après le initViz
?
<!DOCTYPE html>
<html>
<head>
<title>Select Marks</title>
<script type="text/javascript"
src="https://public.tableau.com/javascripts/api/tableau-2.min.js"></script>
<script type="text/javascript">
var viz, sheet;
function initViz() {
var containerDiv = document.getElementById("vizContainer"),
url = "http://public.tableau.com/views/RegionalSampleWorkbook/College",
options = {
"Academic Year": "",
hideTabs: true,
onFirstInteractive: function() {
sheet = viz.getWorkbook().getActiveSheet();
}
};
viz = new tableau.Viz(containerDiv, url, options);
}
function selectCollege(college_name) {
sheet.selectMarksAsync("College", college_name, tableau.SelectionUpdateType.REPLACE);
}
</script>
</head>
<body onload="initViz();">
<div id="vizContainer"></div>
<br />
<button onclick="selectCollege('Engineering');">Select a value</button>
</body>
</html>
'
'(notez le' 'manquant' " 'dans l'exemple que vous avez donné) –Pourquoi ne pas simplement ajouter' selectCollege ('Engineering') 'à la fin de la fonction initViz – Frankusky
Dépend de si vous voulez avant ou après dom a rendu. Vous pouvez simplement exécuter la commande sans init –