gpt4 book ai didi

jquery-ui - jQuery 组合框 : standard script to catch selected value of combobox does not work

转载 作者:行者123 更新时间:2023-12-03 06:47:51 31 4
gpt4 key购买 nike

我正在使用 jqueryui 组合框示例 http://jqueryui.com/demos/autocomplete/combobox.html

我添加了如下所示的脚本来捕获组合框的选定值:

<div id="selectedOpt">
</div>
<script>
$(document).ready(function() {
$("#combobox").change(function() {
var retval = $(this).val();
$("#selectedOpt").html("retval=" + retval);
});
});
</script>

但是,它没有按预期工作:

  1. the div selectedOpt does not show selected value of combobox each time the change event occurs
  2. If "show underlying effect" is selected (pls try at url above), a standard dropdown list appear. When trying to change value of that dropdown list, then the div selectedOpt is able to show value correctly.

目标是让 div selectedOpt 显示组合框的选定选项。请告知并解释为什么(1)不起作用而(2)起作用。

PS:所有必需的js、css均已正确包含。感谢您的关注。

找到解决方案: http://robertmarkbramprogrammer.blogspot.com/2010/09/event-handling-with-jquery-autocomplete.html

最佳答案

请更改您的脚本以匹配以下代码:

<script>
function test()
{
var retval = $("[id *=dropdown] :selected").val();
$("#selectedOpt").html("retval=" + retval);
}
</script>

并从服务器端调用此脚本,如下所示:

dropdown.Attributes.Add("onchange","javascript: return test();")

关于jquery-ui - jQuery 组合框 : standard script to catch selected value of combobox does not work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6352642/

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