gpt4 book ai didi

Javascript 变量似乎是静态的

转载 作者:行者123 更新时间:2023-11-30 12:56:48 24 4
gpt4 key购买 nike

我正在尝试开发一个用 PHP 编写的网站,其中包含一个用户使用它在网站上注册的页面。在选择此页面的国家/地区部分时,我尝试使用 LOOPJ ( http://loopj.com/jquery-tokeninput/demo.html) jQuery 自动完成脚本。当我尝试搜索并制作建议列表时,我想发送位于表单文本框中的另一个字段的数据。所以我尝试使用以下代码:

    $(document).ready(function() {
var countryfrom = $("input#country2").val();
$("#city-input-custom-limits").tokenInput("autocomplete/city_search.php?country=" + countryfrom, {
searchDelay: 1000,
minChars: 3,
tokenLimit: 1
});
});

一切正常。但是当我更改“country2”文本框的值时,countryfrom 的值不会改变并且 country2 的初始值返回到 city_search.php 页面。

谁能提出建议,为什么 country2 更改时 countryfrom 值不更改?

最佳答案

你应该监听 keyup 事件:

// Cache the element
var $elem = $("#city-input-custom-limits");

$("#country2").on('keyup', function() {
var country = $.trim(this.value);
$elem.tokenInput("autocomplete/city_search.php?country=" + country, {
searchDelay: 1000,
minChars: 3,
tokenLimit: 1
});
}).triggerHandler('keyup'); // execute the handler on DOM ready

关于Javascript 变量似乎是静态的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18803515/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com