问题
I'm trying to implement an autocomplete feature to Qualtrics online survey management software. As directed in this feature on the Qualtrics website, I've added the main features of the code to the header of it's Look and Feel section.
<br />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script><script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script><script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script><script>
var $j = jQuery.noConflict();
$j(function() {
var availableTags = [
"Selection 1",
"Selection 2",
"Selection 3"
];
$j( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
Also, I've added this to the specific question block I want the autocomplete feature to be applied to.
Qualtrics.SurveyEngine.addOnload(function() {
jQuery(function() {
jQuery( "#tags" ).autocomplete({source: availableTags});
});
});
I receive no error messages, the text input field just does not call up the tags.
回答1:
Try changing "#tags" to ".InputText". #tags refers to an id that doesn't exist in Qualtrics. .InputText is a class used on text input fields.
Put this in the Qualtrics header (as Anthony recommended):
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<script>
var $j = jQuery.noConflict();
</script>
And this in your question (with NO Qualtrics.SurveyEngine.addOnload) so it only applies to the page with your question on it:
$j(function() {
var availableTags = [
"Selection 1",
"Selection 2",
"Selection 3"
];
$j( ".InputText" ).autocomplete({
source: availableTags
});
});
来源:https://stackoverflow.com/questions/28952275/adding-autocomplete-with-javascript-to-qualtrics