gpt4 book ai didi

javascript - 组合框 jquery onchange 事件

转载 作者:行者123 更新时间:2023-11-28 04:23:52 25 4
gpt4 key购买 nike

我如何根据另一个组合框更新组合框,我有这段代码,但它不起作用,有人可以帮助我。谢谢

  <select name="marca" id="marca" onchange="javascript:carregaModelos(this.value)" >
<option th:each="marca : ${marcas}"
th:value="${marca.idmarca}"
th:text="${marca.nomemarca}">Marca</option>
</select>

<select name="modelo" id="modelo">
<option th:each="modelo : ${modelos}"
th:value="${idmodelo}"
th:text="${nomemodelo}">Modelo</option>
</select>


<script type="text/javascript">
function carregaModelos(marca) {
var opcao = $(this).('#marca option')
console.log(opcao);
jQuery("#modelo").load( "pesquisa/" + opcao);
return false;


}

还有这个

 @RequestMapping("/pesquisa/{idmarca}")
public String pesquisa(ModelMap model, @PathVariable Long idmarca) {
model.addAttribute("modelo", service.obterModelosByMarcas(idmarca));
return "index";

最佳答案

向目标元素添加具有值的属性。

data-target-sync="#targetElementId"

The value is jQuery selector so # included with ID of target element

$(document).ready(function() {

$('[data-target-sync]').change(function() {

var cur = $(this);

$(cur.attr('data-target-sync')).val(cur.val());

});

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select name="marca" id="marca" data-target-sync="#modelo">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>


</select>

<select name="modelo" data-target-sync="#marca" id="modelo">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>

</select>

关于javascript - 组合框 jquery onchange 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45233405/

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