我已经包含使用.js文件的下面的脚本,它不会触发。我对JQuery非常陌生,无法看到我要出错的地方。复选框onChange不会触发
请帮忙。
我现在已经改剧本到下面的以下变化: 使用提阿的示例代码修改我的,现在触发正确的感谢 朱利安$(本).attr(“:检查”)不工作对我来说,因为它返回“未分配”。然而,使用.prop确实$(this).prop('checked')按预期工作(true/false),谢谢 Rashet,为了测试的目的,我将url更改为'/my.script.php',其中包含一个简单的测试脚本和仍然不起作用。
if(isset($_POST['id']) || isset($_POST['Purchased'])){
die('Eureka! variables exist');
}else{
die('Failure!, variables do not exist');
}
$('input[name=Purchased]').change(function(){
//if a checkbox with name 'Purchased' is clicked, do the following.
var id=$(this).attr('id'); //grab the id from the clicked box
var Purchased=$(this).prop('checked');
//alert("ID value:"+id); returns correctly
// alert("Purchase value:"+Purchased); //Returns correctly
//setup the ajax call
//Not posting the variable values to PHP processing script
$.ajax({
type: 'POST',
url: '/my.script.php',
data: {id: 'id',
Purchased: 'Purchased'}
});
});
的URL不正确。您不能引用本地文件系统,并且不能引用当前位置以上的任何内容。 –
如果您的代码包含php和javascript,请添加php标记。 –