是否有机会用jquery更改PHP变量?
我的代码
$(function() {
$('#websites').hide();
$('#main-cat').change(function() {
if ($('#main-cat').val() == 'websites') {
$('#websites').show();
var echo = "<?php echo $ws->websites;?>";
} else {
$('#row_dim').hide();
}
});
});
<div class="form-group" id="websites">
<label class="col-sm-4 col-form-label">Izvēlieties apakškategoriju</label>
<div class="col-sm-8">
<select class="select-general form-control" name="category">
<option label="---Izvēlēties---"></option>
<?php foreach ($websites as $ws){ ?>
<option value="<?php echo **$ws->websites**;?>">
<?php echo $ws->websites;?>
</option>
<?php } ?>
</select>
</div>
</div>
但是我想根据主要类别的选择动态地将$ws->websites
更改为$ws->applications
。
答案 0 :(得分:0)
尝试一下。根据js条件回显代码
var echo="";
if($('#main-cat').val() == 'websites') {
echo = "<?php echo $ws->websites;?>";
} else {
echo = "<?php echo $ws->application;?>";
}