IM試着來填充複選框,並從一個XML文件中使用jquery通過folloowing代碼中設置它們的值...問題是它不工作任何人可以PLZ告訴我什麼即時杜安錯誤通過jQuery的填充從XML複選框
$(document).ready(function(){
$.ajax({
type: "POST",
url: "controls.xml",
dataType: "xml",
success: function(xml) {
var node = $(xml).find('node');
var attribute = $(xml).find('node').attr("attribute");
//TODO: do something with data
$(xml).find('checkbox').each(function() {
var value = $(this).text(); // get the value whether the checkbox is checked or not
var name = $(this).attr("name"); //get the name attribute
var val = $(this).attr("value"); // get the numeric value of the control e.g. 100
$("#Controls").append(//append to some parent container
$("<input/>") // a new input element
.attr("type", "checkbox") //of type checkbox
.attr("name", name) // with given name
.attr("checked", value) // checked="checked" or checked=""
.attr("value", val)//value= specified value
)
});
}
});
});
,這裏是我的xml
<?xml version="1.0" encoding="utf-8" ?>
<RootElement>
<checkbox name="StaticPage" value="100"></checkbox>
<checkbox name="FlashPage" value="200"></checkbox>
<checkbox name="PhotoGalary" value="250"></checkbox>
<checkbox name="CompletePackage" value="1000"></checkbox>
<checkbox name="DiscountPAckage" value="800"></checkbox>
</RootElement>
什麼是你所面對的錯誤/問題? – 2010-11-12 06:12:42
你能給我們一個xml的樣本嗎? – generalhenry 2010-11-12 06:16:41
是你的URL對不對?它說control.xml – kobe 2010-11-12 06:21:11