device_cat_select.php
1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
use yii\helpers\Url;
?>
<select style="width:120px;" class="form-control" name="deviceCatLev1" id="deviceCatLev1">
<option value="">选择分类</option>
<?php foreach ($cat1 as $k => $v) : ?>
<option value="<?= $k ?>" <?php if (isset($selected['deviceCatLev1']) && $k == $selected['deviceCatLev1']) echo 'selected' ?> ><?= $v ?></option>
<?php endforeach; ?>
</select>
<select style="width:120px;" class="form-control" name="deviceCatLev2" id="deviceCatLev2">
<?php if (!empty($cat2)) : ?>
<option value="">选择分类</option>
<?php foreach ($cat2 as $k => $v) : ?>
<option value="<?= $k ?>" <?php if (isset($selected['deviceCatLev2']) && $k == $selected['deviceCatLev2']) echo 'selected' ?> ><?= $v ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
<script>
$(function () {
// 分类2级联动
$('#deviceCatLev1').change(function(){
if ($(this).val() != '') {
var params = 'parentId=' +$(this).val()
$.ajax({
url: "<?= Url::toRoute(['/device/device-cat/ajax-children']) ?>",
type: "GET",
data: params,
success: function (data) {
$('#deviceCatLev2').html(data)
$('#deviceCatLev3').html('')
}
})
} else {
$('#deviceCatLev2').html('')
$('#deviceCatLev3').html('')
}
});
});
</script>