问题:
Uncaught ReferenceError: set_img_func is not defined
at HTMLInputElement.onclick ((index):476)
解决:
<td>
<label>
<input tabindex="1" type="radio" style="vertical-align:middle;" id="set_curr_img_radio" name="radio" value=${image_obj.id} onclick="set_img_func()">
<span style="vertical-align:middle;">当前使用镜像</span>
</label>
</td>
<script>
$(document).ready(function(){
$('.ProjId').click(
function (){
projId=$(this).attr('value');
oldProjId=$.cookie('projId');
if(projId!=oldProjId){
$.cookie('projId', projId, {path: '/', domain: null});
window.location.reload();
}
}
);
//这么写就解决了,不要用function set_img_func(){some code}:
set_img_func = function (){
var radio_val
$('input:radio').each(
function(){
if(this.checked){
radio_val = $(this).val();
$.ajax({
url:'${SITE_URL}image_register/',
type:'POST',
data: JSON.stringify({img_id:$(this).val()}),
headers:{'X-CSRFToken':$.cookie('csrftoken')},
contentType: 'application/json',
dataType: 'json',
success: function(result) {
if (result.code=="200"){
alert('设置成功!')
}
else {
//alert('设置失败!');
}
},
error: function () {
alert('发送失败!');
}
});
}
}
);
};
});
</script>