我想将输入标记的值作为参数(quantita)传递给href。 我应该用javascript来做这件事吗?抱歉我的英文 感谢
<input type="text" id="qta_field" value="${item.value}"/><a href="updateItem?codice=${item.key.codice}&quantita=">update</a>
答案 0 :(得分:8)
使用链接和没有任何库的最简单的方法:
<input type="text" id="qta_field" value="${item.value}"/>
<a href='' onclick="this.href='updateItem?codice=${item.key.codice}&quantita='+document.getElementById('qta_field').value">update</a>
答案 1 :(得分:3)
要将数据从输入发送到服务器,您应该使用表单。
<form action="updateItem">
<input id="qta_field" name="quantita" value="${item.value}">
<input type="hidden" name="codice" value="${item.key.codice}">
<button>update</button>
</form>
答案 2 :(得分:1)
为<a>
设置ID或类,例如:<a id='myA'>
所以你可以像这样使用jQuery:
jQuery(document).ready(function(){
jQuery('qta_field').change(function(){
var tmpVal = jQuery('#qta_field').val();
var tmphref = jQuery('#myA').attr('href');
tmphref = tmphref+tmpVal;
jQuery('#myA').attr('href',tmphref);
});
});
答案 3 :(得分:1)
您可以使用document.queryselector使用js
定位和操作href属性示例:
input = document.querySelector('input');
a = document.querySelector('a');
a.setAttribute('href',a.getAttribute('href')+input.value);
<input type="text" id="qta_field" value="test"/>
<a href="updateItem?codice=${item.key.codice}&quantita=">update</a>