我有一个jquery函数,包括html选择和输入,它显示带有可选值名称的表单是olcu
<script type="text/javascript">
$(document).ready(function() {
$("#add").click(function() {
var intId = $("#buildyourform div").length + 1;
var fieldWrapper = $("<div class=\"fieldwrapper\" id=\"field" + intId + "\"/>");
var fMiktar = $("<input type=\"text\" class=\"miktar\" name=\"miktar[]\" size=\"6px\" />");
var fOlcu = $("<select class=\"olcu\" name=\"olcu[]\"><option value=\"Adet\">Adet</option><option value=\"Metre\">Metre</option><option value=\"Gram\">Gram</option></select>");
var fMalzeme = $("<input type=\"text\" name=\"malzeme[]\" class=\"malzeme\" id=\"aramayap\" />");
var removeButton = $("<input type=\"button\" class=\"remove\" value=\"-\" />");
removeButton.click(function() {
$(this).parent().remove();
});
fieldWrapper.append(fMiktar);
fieldWrapper.append(fOlcu);
fieldWrapper.append(fMalzeme);
fieldWrapper.append(removeButton);
$("#buildyourform").append(fieldWrapper);
});
});
</script>
我想从数据库中获取olcu的值
这是数据库代码
<script type="text/javascript">
function showSelected(val){
document.getElementById ('selectedResult').innerHTML = "" + val;
}
</script>
<select name="olcu[]" onChange='showSelected(this.value)' class="olcu" id="olcu">Olcu Sec/option>
<?php
while($olculer=mysql_fetch_array($hangiolcu)){
echo "<option value='$olculer[olcu]'>$olculer[olcu]</option>";
}
?>
</select>
如何将该sql代码附加或替换为此jquery行
var fOlcu = $("<select class=\"olcu\" name=\"olcu[]\"><option value=\"Adet\">Adet</option><option value=\"Metre\">Metre</option><option value=\"Gram\">Gram</option></select>");
答案 0 :(得分:2)
您可以使用以下PHP代码创建Javascript / jQuery变量:
var foo = '<?php //echo or return php value here; ?>';