我試圖制作一個X-editable "combodate",用戶可以點擊它,通過AJAX即時更新資料庫。
前兩個示例可以作業,但是一旦我將型別改為 "combodate",就會出現 "腳本錯誤"。
。$(document)。 ready(function() {
//ajax emulation
$.mockjax({
url: '/post',
responseTime: 200,
response: function(settings) {
if (settings.data.value) {
this.responseText = '{"success": true}'/span>;
} else {
this.responseText = '{'success": false, "msg": "required"}'。
}
}
});
//這個可以。
$('#username').editable({
type: 'text',
url: '/post'。
pk: 1,
title: '輸入用戶名'。
ajaxOptions: {
dataType: 'json'。
},
success: function(response, newValue) {
if (! response) {
return "未知錯誤!"。
}
if (response.success === false) {
return response.msg;
}
}
});
//這個也可以。
$("#date1").editable({
/* type: 'combodate', */.
url: '/post'。
pk: 490,
title: 'Enter date',
ajaxOptions: {
dataType: 'json'。
},
success: function(response, newValue) {
if (! response) {
return "未知錯誤!"。
}
if (response.success === false) {
return response.msg;
}
}
});
//這一個不起作用...
$("#date2").editable()。
/* $("#date2").editable({
type: 'combodate',
網址。'/post',
pk: 490,
title: '輸入日期',
ajaxOptions: {
dataType: 'json'.
},
成功:函式(回應,新值) {
if(!response) {
回傳 "未知錯誤!"。
}
如果(response.success === false) {
回傳 response.msg。
}
}
}); */
//這個也不能用
//$("#date3").editable();
});
<head>
<link href="//netdna.bootstrapcdn. com/bootstrap/3.0.0/css/bootstrap.min.css" rel="styleheet">
<script src="http://code. jquery.com/jquery-2.0.3.min.js"></script>
<script src="//netdna. bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>/span>
<script src="https://cdnjs.cloudflare. com/ajax/libs/jquery-mockjax/1.6.2/jquery.mockjax.js"></script>/span>
<link href="/cdnjs.cloudflare.com/ajax/libs/x-editable/1. 5.0/bootstrap3-editable/css/bootstrap-editable.css" rel="styleheet" />
<script src="/cdnjs. cloudflare.com/ajax/libs/x-editable/1.5.0/bootstrap3-editable/js/bootstrap-editable.min.js">/span>
</script>/span>
</head>
<body>
<p>X-editable: process JSON response.</p>
<p>用戶名欄位可以使用,#date1也可以使用,但是一旦我把型別改為 "combodate",我就得到 "腳本錯誤"。</p>
<div style="margin: 5px">/span>
<ol>
<li>
<a id="用戶名" href="#"> awesome</a>/span>
</li>/span>
<li>/span>
<a id="date1"/span> href="#"/span>> 2021-01-01</a>/span>
</li>/span>
<li>/span>
< a id="date2" href="#" data-type="combodate"> 2021-01-02</a>。
</li>/span>
<li>/span>
< a href="#"/span> id="date3" data-type="combodate" data-value="1984-05-15" data-format="YYY-MM-DD" data-viewformat="DD/MM/YYYY" data-template="D / MMM / YYYY" data-pk="1" data-title="選擇出生日期" class="可編輯編輯-點擊可編輯-打開" data-original-title="
title="">2021-01-03</a>/span>
</li>/span>
</ol>/span>
</div>/span>
</body>/span>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
我需要包括 moment.js
<script。
src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"/span>
integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8 M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ=="/span>
crossorigin="anonymous"。
referrerpolicy="no-referrer"/span>>
</script>/span>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/309214.html
標籤:
