使用来自loopj.com的jQuery tokeninput
我可以选择从 .jsp 文件以 JSON 格式发送的多个选项。但是,当我想提交/访问文本输入元素“tokenize”中的值时,我得到未定义的输出。我是java脚本的新手,所以什么该碰,什么不该碰。
问:有人可以向我提供/指出如何尽早实现这一目标的一些细节吗? 下面是不是少了点什么?
提前致谢, Aditya
注意: body 标签被分割成一个单独的代码块。请不要混淆。
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" />
<script src="http://www.google.com/jsapi"> </script>
<script>
google.load("jquery", "1");
</script>
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<script type="text/javascript" src="js/jquery.tokeninput.js"></script>
<link rel="stylesheet" href="css/token-input.css" type="text/css" />
<link rel="stylesheet" href="css/token-input-facebook.css" type="text/css" />
<style>
input {
font-size: 120%;
}
</style>
<script type="text/javascript">
function showList()
{
t = document.getElementById('tokenize').valueOf();
alert(t); //DISPLAYS 'undefined' <- LOOK HERE
}
</script>
<h1>Jquery Tokenizing Autocomplete Input</h1>
<form name="myForm">
<div>
<h2>List style</h2>
<input type="text" id="tokenize" name="blah"/> <br>
<input type="submit" value="Parse" onClick="showList()"/>
</div>
<div>
<h2>Facebook style</h2>
<input type="text" id="tokenize2" name="blah2" />
</div>
</form>
<!-- <script type="text/javascript">
$("#country").autocomplete("getData.jsp",
{'multiple': true, 'multipleSeparator': ','});
</script> -->
<script type="text/javascript">
$(document).ready(function() {
$("#tokenize").tokenInput("getData.jsp", {
hintText: "Type in the names of your favorite TV shows",
noResultsText: "No results",
searchingText: "Searching..."
});
$("#tokenize2").tokenInput("getData.jsp", {
classes: {
tokenList: "token-input-list-facebook",
token: "token-input-token-facebook",
tokenDelete: "token-input-delete-token-facebook",
selectedToken: "token-input-selected-token-facebook",
highlightedToken: "token-input-highlighted-token-facebook",
dropdown: "token-input-dropdown-facebook",
dropdownItem: "token-input-dropdown-item-facebook",
dropdownItem2: "token-input-dropdown-item2-facebook",
selectedDropdownItem: "token-input-selected-dropdown-item-facebook",
inputToken: "token-input-input-token-facebook"
}
});
});
</script>
I am able to select multiple options that I send from my .jsp file in JSON format. However, when I want to SUBMIT/access the values from the text input element "tokenize", I get a undefined output. I am a novice to java script and so what to touch and what not to touch.
Q: Could someone provide/point me to some detail on how to achieve this at the earliest??
Is there something missing below?
Thnx in Advance,
Aditya
Note: The body tag got split into a separate code block. Pls donot get confused.
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" />
<script src="http://www.google.com/jsapi"> </script>
<script>
google.load("jquery", "1");
</script>
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<script type="text/javascript" src="js/jquery.tokeninput.js"></script>
<link rel="stylesheet" href="css/token-input.css" type="text/css" />
<link rel="stylesheet" href="css/token-input-facebook.css" type="text/css" />
<style>
input {
font-size: 120%;
}
</style>
<script type="text/javascript">
function showList()
{
t = document.getElementById('tokenize').valueOf();
alert(t); //DISPLAYS 'undefined' <- LOOK HERE
}
</script>
<h1>Jquery Tokenizing Autocomplete Input</h1>
<form name="myForm">
<div>
<h2>List style</h2>
<input type="text" id="tokenize" name="blah"/> <br>
<input type="submit" value="Parse" onClick="showList()"/>
</div>
<div>
<h2>Facebook style</h2>
<input type="text" id="tokenize2" name="blah2" />
</div>
</form>
<!-- <script type="text/javascript">
$("#country").autocomplete("getData.jsp",
{'multiple': true, 'multipleSeparator': ','});
</script> -->
<script type="text/javascript">
$(document).ready(function() {
$("#tokenize").tokenInput("getData.jsp", {
hintText: "Type in the names of your favorite TV shows",
noResultsText: "No results",
searchingText: "Searching..."
});
$("#tokenize2").tokenInput("getData.jsp", {
classes: {
tokenList: "token-input-list-facebook",
token: "token-input-token-facebook",
tokenDelete: "token-input-delete-token-facebook",
selectedToken: "token-input-selected-token-facebook",
highlightedToken: "token-input-highlighted-token-facebook",
dropdown: "token-input-dropdown-facebook",
dropdownItem: "token-input-dropdown-item-facebook",
dropdownItem2: "token-input-dropdown-item2-facebook",
selectedDropdownItem: "token-input-selected-dropdown-item-facebook",
inputToken: "token-input-input-token-facebook"
}
});
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
代替:
使用
Instead of:
use