-5
//這裏str是一個變量,我只是想PHP變量賦值給變量SRT,但我得到一個錯誤,即: -我沒有得到下拉列表,此代碼
Parse error: syntax error, unexpected 'var' (T_VAR)
<script>
<?php
while($rowss = mysql_fetch_array($result2, MYSQL_ASSOC)){
?>
var str = <?php echo $rowss["ingredient"];?>;
var str_array = str.split(',');
for(var i = 0; i < str_array.length; i++) {
// Trim the excess whitespace.
str_array[i] = str_array[i].replace(/^\s*/, "").replace(/\s*$/, "");
// Add additional code here, such as:
var opt = document.createElement('option');
opt.innerHTML = str_array[i];
opt.value = str_array[i];
sel.appendChild(opt);
}
}
</script>
https://eval.in/682550和https://eval.in/682552 –
@RuchishParikh內'php'文件'變種str'不會辨認,直到它成爲內側''
另一種方法可能是用PHP生成一個數組,其中包含所有
ingredients
,稍後將其指定爲javascript中的變量。來源
2016-11-22 09:23:50 RamRaider
我無法生成下拉菜單。請幫幫我。 –