我有一个 web 表单,当页面加载时,它会根据存储在 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"}]
查询:
$.getJSON("jason.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>
这不起作用:
<li><input type="checkbox" name="merk[]" value="Levi's"/>Levi's</li>