href
我有一个 JQuery 函数可以在添加或删除属性时更改按钮的颜色。如果我用模糊启动它,它会完美地工作
$("#name").blur(function() {
var standards_name = $("#name").val();
var standards_link = $("#standardslink");
var update_log = $("#update_log");
if(jQuery.inArray(standards_name, standards) != -1) {
if(companyid !== null) {
standards_link.attr("href", basic_href + "?standards_name=" + standards_name + "&company_id=" + companyid);
} else {
standards_link.attr("href", basic_href + "?standards_name=" + standards_name);
}
standards_link.css("color","#2EE52B");
} else if(standards_name == "") {
standards_link.removeAttr("href");
standards_link.css("color","black");
update_log.hide();
} else {
standards_link.removeAttr("href");
standards_link.css("color","#FF0011");
update_log.hide();
}
});
但希望它在自动完成下拉列表中的选择上启动。这是我无法再进一步的地方。如果我手动设置变量“standards_name”,粘贴的代码就可以工作,例如,var standards_name = "xxxx";
但我希望将ui.item.ticker_name
值传递给变量。(“standards”数组和“companyid”PHP
json_encode
在脚本中较早地设置和传递,并且工作正常)
这是代码:
$(function() {
$("#name").autocomplete({
source: "../autocomplete.php",
minLength: 2,
select: function(event, ui) {
$('#name').val(ui.item.ticker_name);
$('#mktcap').val(ui.item.mkt_cap);
var standards_name = ui.item.ticker_name;
var standards_link = $("#standardslink");
var update_log = $("#update_log");
if(jQuery.inArray(standards_name, standards) != -1) {
if(companyid !== null) {
standards_link.attr("href", basic_href + "?standards_name=" + standards_name + "&company_id=" + companyid);
} else {
standards_link.attr("href", basic_href + "?standards_name=" + standards_name);
}
standards_link.css("color","#2EE52B");
} else if(standards_name == "") {
standards_link.removeAttr("href");
standards_link.css("color","black");
update_log.hide();
} else {
standards_link.removeAttr("href");
standards_link.css("color","#FF0011");
update_log.hide();
}
}
});
});