问题
I am using this http://code.drewwilson.com/entry/autosuggest-jquery-plugin
Here is my html
<h1>Category : </h1>
<input type="text" name="category" id="category" size="4"/>
<input type="button" name="category" id="gocategory" value="Go"/>
here is my jquery code :
$(document).ready(function() {
// put all your jQuery goodness in here.
var data = {items: [
{value: "21", name: "Mick Jagger"},
{value: "43", name: "Johnny Storm"},
{value: "46", name: "Richard Hatch"},
{value: "54", name: "Kelly Slater"},
{value: "55", name: "Rudy Hamilton"},
{value: "79", name: "Michael Jordan"}
]};
$("#category").autoSuggest(data.items, {selectedItemProp: "name", searchObjProps: "name"});
// $("#category").autoSuggest("http://mysite.com/path/to/script", {minChars: 2, matchCase: true});;
$("#gocategory").click(function(){
alert($("#category").value);
});
});
How i will get the value of the selected category in the onclick event ?
回答1:
with option
asHtmlID:"rech"
(rech is a sample name) the value save in it with comma seperator and it's be hidden field which can get value with
$("input[name='as_values_rech']").val()
if dont set "asHtmlID" ... , autoSuggest give a random name for it, and in your code:
$("#category").autoSuggest(data.items, {selectedItemProp: "name", searchObjProps: "name" ,
selectedValuesProp:"value",asHtmlID:"rech"});
$("#gocategory").click(function(){
alert($("input[name='as_values_rech']").val());
});
回答2:
Maybe using .val() will do the trick. I'm not familiar with this plugin thou.
alert($("#category").val());
回答3:
There is an event onsubmit or something like tis on each selection that function is executed .so by that way we can get the value.
来源:https://stackoverflow.com/questions/5417022/how-to-get-value-of-autosuggest-plugin