我已经构建了一个表单,该表单使用JSON从MYSQL数据库中提取品牌列表。引入的品牌应该改变表格中相应的输入品牌元素。但出于某种原因,我没有让这个工作。
我的代码:
JSON
[{"pkFavorietemerken":"1","merken":"Adidas"},{"pkFavorietemerken":"2","merken":"Boss"},{"pkFavorietemerken":"3","merken":"Burberry"},{"pkFavorietemerken":"4","merken":"Christian Dior"},{"pkFavorietemerken":"5","merken":"D&G"},{"pkFavorietemerken":"6","merken":"Diesel"},{"pkFavorietemerken":"7","merken":"Dolce & Gabanna"},{"pkFavorietemerken":"8","merken":"Emporio Armani"}]
JQUERY:
$("document").ready(function(){
$.getJSON("jason2.php", function(data) {
$.each(data, function(){
$("[value=this.merken]").attr("checked","checked");
});
});
HTML:
<form name="form1" method="post" action="something.php">
<ul>
<li><input type="checkbox" name="merk[]" value="Adidas"/>Adidas</li>
<li><input type="checkbox" name="merk[]" value="Airforce"/>Airforce</li>
<li><input type="checkbox" name="merk[]" value="Armani"/>Armani</li>
<li><input type="checkbox" name="merk[]" value="Asics"/>Asics</li>
<li><input type="checkbox" name="merk[]" value="Bikkemberg"/>Bikkemberg</li>
<li><input type="checkbox" name="merk[]" value="Bjorn Borg"/>Bjorn Borg</li>
<li><input type="checkbox" name="merk[]" value="BlueBlood"/>BlueBlood</li>
<li><input type="checkbox" name="merk[]" value="Boss"/>Boss</li>
<li><input type="checkbox" name="merk[]" value="Brunotti"/>Brunotti</li>
<li><input type="checkbox" name="merk[]" value="Burberry"/>Burberry</li>
</ul>
</form>
答案 0 :(得分:2)
尝试更换:
$("[value=this.merken]").attr("checked","checked");
使用:
$("[value='" + this.merken + "']").attr("checked","checked");