我有一个代码,它将根据循环的计数显示选择和文本框。选择下拉列表将以首字母缩略词格式显示货币。例如,如果选择美元,文本框将显示"美元"。在第二个循环中,如果我选择日元,它将在第二行的文本框中显示日元,以此类推。这在jquery上可能吗?
这是我的代码
<script>
$(document).ready(function(){
$('#acr').change(function(){
//get json + this.value get corresponding value on db
//retrieve data
});
});
</script>
<?php
foreach($data as $d) {
?>
<select name = "acr" id = "acr">
//Records from db
</select>
<input type = "text" readonly value = ""> <br>
<?
}
??
是。但首先请为您的文本框指定一个name属性,并假设其id为"longName"。您可能有两种选择:
选项1:在select中保存货币短名称/长名称。JPY代码:
$('#acr').change(function(){
$('#longName').val($(this).val());
});
选项2:
$('#acr').change(function(){
var sel = $(this);
$.ajax({
url: "your url",
type: "POST",
data: 'data='+sel.val(),
dataType:'json',
success: function(data) {
//Do what ever you want. Data holds the response from server
},
error: function() {
//Error occured, handle it
}
});
});
点击此处阅读更多关于ajax的信息