我发现了很多我正在尝试做的事情的例子。不幸的是,我无法让任何工作:)
我需要一个文本框来更改所选下拉列表的值。
我创建了一个 fiddle 。
我尝试使用的 JS 是
$(document).ready(function() {
$("#goal option").filter(function() {
return $(this).val() == $("#reason").val();
}).attr('selected', true);
$("#goal").live("change", function() {
$("#reason").val($(this).find("option:selected").attr("value"));
});
});
https://jsfiddle.net/phpman13/q8h5kupj/
我尝试使用 FireBug,但它报告 .live 无效。
有什么想法吗?
最佳答案
.live() 已弃用,使用 .on() 代替。它遵循相同的语法。
来自:https://api.jquery.com/live/
As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live().
关于用于选择/文本框操作的 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29516829/