[<div class="col-md-5">
<input type="text" class="form-control input" id="formula" name="formula1" placeholder="Enter formula" value="">
<input type="text" class="form-control input" id="mformula" name="mformula" disabled="true">
</div>
此代码工作正常但我需要点击(+, - ,*)运算符,然后将其值设置为输入字段并显示tag-it属性。
当我点击运算符时,我想将该值推入输入字段并显示tag-it的属性。 对于keyup方法,这个代码工作正常。但是当我点击operator时它不会进入输入字段而不显示tag-it属性(用于自动完成)。
$("#plus").click(function () {
var value = $(this).val();
$('input[name=formula1]').val(value);
});
$(function () {
$(document).on("keyup", "#formula", function () {
var val = $(this).val();
if (val == '+' || val == '-' || val == '*' || val == '/' || val == '(' || val == ')' || val == 'MonthlyAverageOf') {
var sampleTags = ['/', '*', '-', '+', '(', ')','MonthlyAverageOf'];
//-------------------------------
// Minimal
//-------------------------------
$('#myTags').tagit();
//-------------------------------
// Single field
//-------------------------------
$('#formula').tagit({
availableTags: sampleTags,
// This will make Tag-it submit a single form value, as a comma-delimited field.
singleField: true,
singleFieldNode: $('#mformula')
});
// formula2 is an INPUT element, rather than a UL as in the other
// examples, so it automatically defaults to singleField.
$('#formula2').tagit({
availableTags: sampleTags
});
//-------------------------------
// Preloading data in markup
//-------------------------------
$('#myULTags').tagit({
availableTags: sampleTags, // this param is of course optional. it's for autocomplete.
// configure the name of the input field (will be submitted with form), default: item[tags]
itemName: 'item',
fieldName: 'tags'
});
//-------------------------------
// Tag events
//-------------------------------
var eventTags = $('#eventTags');
var addEvent = function (text) {
$('#events_container').append(text + '<br>');
};
//alert(eventTags);
eventTags.tagit({
availableTags: sampleTags,
beforeTagAdded: function (evt, ui) {
if (!ui.duringInitialization) {
addEvent('beforeTagAdded: ' + eventTags.tagit('tagLabel', ui.tag));
}
},
afterTagAdded: function (evt, ui) {
if (!ui.duringInitialization) {
addEvent('afterTagAdded: ' + eventTags.tagit('tagLabel', ui.tag));
}
},
beforeTagRemoved: function (evt, ui) {
addEvent('beforeTagRemoved: ' + eventTags.tagit('tagLabel', ui.tag));
},
afterTagRemoved: function (evt, ui) {
addEvent('afterTagRemoved: ' + eventTags.tagit('tagLabel', ui.tag));
},
onTagClicked: function (evt, ui) {
addEvent('onTagClicked: ' + eventTags.tagit('tagLabel', ui.tag));
},
onTagExists: function (evt, ui) {
addEvent('onTagExists: ' + eventTags.tagit('tagLabel', ui.existingTag));
}
});
//-------------------------------
// Read-only
//-------------------------------
$('#readOnlyTags').tagit({
readOnly: true
});
//-------------------------------
// Tag-it methods
//-------------------------------
$('#methodTags').tagit({
availableTags: sampleTags
});
//-------------------------------
// Allow spaces without quotes.
//-------------------------------
$('#allowSpacesTags').tagit({
availableTags: sampleTags,
allowSpaces: true
});
//-------------------------------
// Remove confirmation
//-------------------------------
$('#removeConfirmationTags').tagit({
availableTags: sampleTags,
removeConfirmation: true
});
} else {
var sampleTags = <?php include('auto.php'); ?>;
//-------------------------------
// Minimal
//-------------------------------
$('#myTags').tagit();
//-------------------------------
// Single field
//-------------------------------
$('#formula').tagit({
availableTags: sampleTags,
// This will make Tag-it submit a single form value, as a comma-delimited field.
singleField: true,
singleFieldNode: $('#mformula')
});
// formula2 is an INPUT element, rather than a UL as in the other
// examples, so it automatically defaults to singleField.
$('#formula2').tagit({
availableTags: sampleTags
});
//-------------------------------
// Preloading data in markup
//-------------------------------
$('#myULTags').tagit({
availableTags: sampleTags, // this param is of course optional. it's for autocomplete.
// configure the name of the input field (will be submitted with form), default: item[tags]
itemName: 'item',
fieldName: 'tags'
});
//-------------------------------
// Tag events
//-------------------------------
var eventTags = $('#eventTags');
var addEvent = function (text) {
$('#events_container').append(text + '<br>');
};
eventTags.tagit({
availableTags: sampleTags,
beforeTagAdded: function (evt, ui) {
if (!ui.duringInitialization) {
addEvent('beforeTagAdded: ' + eventTags.tagit('tagLabel', ui.tag));
}
},
afterTagAdded: function (evt, ui) {
if (!ui.duringInitialization) {
addEvent('afterTagAdded: ' + eventTags.tagit('tagLabel', ui.tag));
}
},
beforeTagRemoved: function (evt, ui) {
addEvent('beforeTagRemoved: ' + eventTags.tagit('tagLabel', ui.tag));
},
afterTagRemoved: function (evt, ui) {
addEvent('afterTagRemoved: ' + eventTags.tagit('tagLabel', ui.tag));
},
onTagClicked: function (evt, ui) {
addEvent('onTagClicked: ' + eventTags.tagit('tagLabel', ui.tag));
},
onTagExists: function (evt, ui) {
addEvent('onTagExists: ' + eventTags.tagit('tagLabel', ui.existingTag));
}
});
//-------------------------------
// Read-only
//-------------------------------
$('#readOnlyTags').tagit({
readOnly: true
});
//-------------------------------
// Tag-it methods
//-------------------------------
$('#methodTags').tagit({
availableTags: sampleTags
});
//-------------------------------
// Allow spaces without quotes.
//-------------------------------
$('#allowSpacesTags').tagit({
availableTags: sampleTags,
allowSpaces: true
});
//-------------------------------
// Remove confirmation
//-------------------------------
$('#removeConfirmationTags').tagit({
availableTags: sampleTags,
removeConfirmation: true
});
}
});
var sampleTags =<?php include('auto.php'); ?>;
//-------------------------------
// Minimal
//-------------------------------
$('#myTags').tagit();
//-------------------------------
// Single field
//-------------------------------
$('#formula').tagit({
availableTags: sampleTags,
// This will make Tag-it submit a single form value, as a comma-delimited field.
singleField: true,
singleFieldNode: $('#mformula')
});
// formula2 is an INPUT element, rather than a UL as in the other
// examples, so it automatically defaults to singleField.
$('#formula2').tagit({
availableTags: sampleTags
});
//-------------------------------
// Preloading data in markup
//-------------------------------
$('#myULTags').tagit({
availableTags: sampleTags, // this param is of course optional. it's for autocomplete.
// configure the name of the input field (will be submitted with form), default: item[tags]
itemName: 'item',
fieldName: 'tags'
});
//-------------------------------
// Tag events
//-------------------------------
var eventTags = $('#eventTags');
var addEvent = function (text) {
$('#events_container').append(text + '<br>');
};
eventTags.tagit({
availableTags: sampleTags,
beforeTagAdded: function (evt, ui) {
if (!ui.duringInitialization) {
addEvent('beforeTagAdded: ' + eventTags.tagit('tagLabel', ui.tag));
}
},
afterTagAdded: function (evt, ui) {
if (!ui.duringInitialization) {
addEvent('afterTagAdded: ' + eventTags.tagit('tagLabel', ui.tag));
}
},
beforeTagRemoved: function (evt, ui) {
addEvent('beforeTagRemoved: ' + eventTags.tagit('tagLabel', ui.tag));
},
afterTagRemoved: function (evt, ui) {
addEvent('afterTagRemoved: ' + eventTags.tagit('tagLabel', ui.tag));
},
onTagClicked: function (evt, ui) {
addEvent('onTagClicked: ' + eventTags.tagit('tagLabel', ui.tag));
},
onTagExists: function (evt, ui) {
addEvent('onTagExists: ' + eventTags.tagit('tagLabel', ui.existingTag));
}
});
//-------------------------------
// Read-only
//-------------------------------
$('#readOnlyTags').tagit({
readOnly: true
});
//-------------------------------
// Tag-it methods
//-------------------------------
$('#methodTags').tagit({
availableTags: sampleTags
});
//-------------------------------
// Allow spaces without quotes.
//-------------------------------
$('#allowSpacesTags').tagit({
availableTags: sampleTags,
allowSpaces: true
});
//-------------------------------
// Remove confirmation
//-------------------------------
$('#removeConfirmationTags').tagit({
availableTags: sampleTags,
removeConfirmation: true
});
});