我正在开发chrome扩展程序。我能够使用“输入”键添加标签。但是,即使我已经指定了空格,也无法将“空格键”用作确认键。 Google返回:
Uncaught SyntaxError: Unexpected token ;
尽管我能够添加标签,但我的预填充标签功能也返回错误:
Uncaught TypeError: $(...).tagsinput is not a function
请帮帮我。
popup.js:
var reddits = ["Art"];
var exists = localStorage.getItem('redditList');
if(exists) {
reddits = JSON.parse( exists );
}
$.each(reddits, function(index, value) {
$('#Tags').tagsinput('add', value); // Uncaught TypeError: $(...).tagsinput is not a function
console.log(index, value);
});
$('#Tags').tagsinput({
confirmKeys: [13, 32] // Uncaught SyntaxError: Unexpected token ;
});
$('input').on('itemAdded', function(event) {
var sub = String(event.item);
sub = sub.replace(/\s/g, '');
reddits.push(sub);
console.log(reddits);
saveList();
});
$('input').on('itemRemoved', function(event) {
reddits.splice(reddits.indexOf(event.item), 1);
console.log(reddits);
saveList();
});
function saveList() {
localStorage.setItem('redditList', JSON.stringify(reddits));
reddits = JSON.parse( localStorage.getItem('redditList'));
}
popup.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Simple Chrome Extension</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap-tagsinput.css">
</head>
<body>
<div class="inputContainer">
<input type="text" id="Tags" class="form-control"/>
</div>
<script src="jquery-2.2.4.min.js"></script>
<script src="bootstrap.min.js"></script>
<script src="bootstrap-tagsinput.js"></script>
<script type="text/javascript" src="js/popup.js"></script>
</body>
</html>