我需要什么
js code
var industrys=[];
for (var b = 0; b < obj.industry.length; b++)
{
var indus=obj.industry[b];
var temp = new Object();
temp["value"] =indus.industry_url;
temp["data"] = indus.id;
industrys.push(temp);
}
$('.autocomplete_ind').autocomplete({
lookup: industrys,
onSelect: function(suggestion) {
make_url('', suggestion.value);
var thehtml = '<strong>industry name:</strong> ' + suggestion.name + ' selected<br> <strong>'+ suggestion.id+'</strong>';
$('#outputcontent').html(thehtml);
$(this).attr("value", suggestion.value);
}
html
<input type="text" autocomplete="off" onChange="make_url()"
id="industry_name" class="biginput autocomplete_ind"
value="all data">
问题
我试过$(this).attr(“value”,suggestion.value);但是在变革事件中,它反映了价值 - “blala等”。
但刷新或重定向值未附加
<input type="text" autocomplete="off" onchange="make_url()" id="industry_name" class="biginput autocomplete_ind" placeholder="All Industry" value="All industry">
现在$(this).attr(“value”,suggestion.value);执行
<input type="text" autocomplete="off" onchange="make_url()" id="industry_name" class="biginput autocomplete_ind" placeholder="All Industry" value="agriculture-forestry">
但是在查看源值的页面刷新或重定向时不存在。
答案 0 :(得分:2)
data()
用于设置data-*
属性的值。
使用val()
设置元素值。
更改
$(this).data('value', suggestion.value);
要
$(this).val(suggestion.value);
修改强>
使用append()
更改
$('#outputcontent').html(thehtml);
要
$('#outputcontent').append(thehtml);