我正在使用PHP。当用户从组合框中选择任何项目时,相应的项目将显示在第二个组合框中。我需要将第二个组合框值存储到文本框中以供进一步使用。
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$('#combo').change(function(){
console.log($(this));
$.get( "abc.php" , { option : $(this).val() } , function ( data ) {
$ ( '#comboB' ) . html ( data ) ;
} ) ;
});
});
</script>
</head>
<body>
<form>
<select name="combo" id="combo">
<option value="">-- Select</option>
<option value="1"> Personnel</option>
<option value="2"> Area Layout</option>
<option value="3">Conference Rooms</option>
<option value="4"> Small Office</option>
</select>
now abc.php
<?php
$Options = Array (
1 => Array (
'--',
'15 x 20 (300 sq. ft.)' ,
'15’ x 15’ (225 sq. ft.)',
' 10’ x 15’ (150 sq. ft.)',
'12’ x 10’ (120 sq. ft.)'
) ,
2 => Array (
'10’ x 10’ (100 sq. ft.)' ,
' 8’ x 6’ (48 sq. ft.)',
'5’ x 5’ (25 sq. ft.)'
) ,
3 => Array (
'15’ x 25’ (375 sq. ft.)' ,
'15’ x 20’ (300 sq. ft.)',
'15’ x 15’ (225 sq. ft.)'
) ,
4 => Array (
'8’ x 8’ (64 sq. ft.)' ,
'8’ x 6’ (48 sq. ft.)',
'6’ x 6’ (36 sq. ft.)',
'4’ x 6’ (24 sq. ft.)'
)
) ;
forEach ( $Options [ $_GET [ 'option' ] ] as $Item ) {
printf ( '<option value="%s">%s</option>' , $Item , $Item ) ;
}
?>
答案 0 :(得分:0)
javascript代码如:
$('#comboB').change(function(){ $('#textbox').val($(this).val()); });
会做的伎俩
关于如何修改HTML的编辑示例
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$('#combo').change(function(){
console.log($(this));
$.get( "abc.php" , { option : $(this).val() } , function ( data ) {
$ ( '#comboB' ) . html ( data ) ;
} ) ;
});
$('#comboB').change(function(){ $('#textboxB').val($(this).val()); });
});
</script>
</head>
<body>
<form>
<select name="combo" id="combo">
<option value="">-- Select</option>
<option value="1"> Personnel</option>
<option value="2"> Area Layout</option>
<option value="3">Conference Rooms</option>
<option value="4"> Small Office</option>
</select>
</form>
<select id="comboB"></select>
<input type="textbox" id="textboxB" value="" />