我有这个array = var1;var2;var3;var4;var5;var6;var6
我想用jQuery拆分它,并把它放在不同的文本框(txt1),(txt2)...etc中,但我找不到正确的代码。
<script type="text/javascript">
$(document).ready(function() {
$("#cb_motor").change(function() {
$("#cb_motor option:selected").each(function() {
cb_motor = $('#cb_motor').val();
$.post("http://localhost/sag_app/index.php/motor/motor/buscar_id/", {
cb_motor : cb_motor
}, function(data) {
valores = data.split(';');
});
});
})
});
</script> 发布于 2014-05-14 00:48:01
假设cb_motor是一个不带多个值的select,则可以简化代码
$(function() {
$("#cb_motor").change(function() {
$.post("http://localhost/sag_app/index.php/motor/motor/buscar_id/", {
cb_motor : $(this).val()
}, function(data) {
var valores = data.split(';');
$('[name="txt_num_serie_motor"]').each(function(i) {
$(this).val(valores[i]);
});
});
});
});如果它是multiple,那么您不能对所选值使用each进行Ajax,因为您需要等待每个调用返回
发布于 2014-05-14 00:52:52
如果txt1, txt2是输入ID,并且是按照DOM顺序设置的,则可以使用:
$("[id^=txt]").val(function(i){
return valores[i];
});https://stackoverflow.com/questions/23637044
复制相似问题