下面的代码显示了日期框模式弹出窗口中的一个按钮,但我希望清除我点击按钮的日期。我尝试了很多东西,但是不能通过jQuery方法做到这一点。
<zk>
<script>
zk.afterLoad('zul.db', function () {
var _xRenderer = {};
zk.override(zul.db.Renderer, _xRenderer, {
titleHTML: function (wgt, out, localizedSymbols) {
_xRenderer.titleHTML.apply(this, arguments); //call the original method
var uuid = wgt.uuid,
view = wgt._view,
text = wgt.getZclass() + '-ctrler';
if(view == 'day') {
out.push('<button id="', uuid, '-today" class="', text, '"',
' onClick="var cal = zk.Widget.$(\'$', wgt.parent.id, '\')._pop; cal._value = null; cal._setTime();"',
' >', ' today', '</button>');
}
out.push('<button id="', uuid, '-clear" class="', text, '"',
' onClick="alert(jq(this.parent.$n()))"',
' >', ' clear', '</button>');
}
});
});
</script>
<datebox id="db" ></datebox>
</zk>
答案 0 :(得分:1)
在你的情况下,clear按钮是datebox的子dom而不是子widget,this.parent。$ n()仅在按钮是datebox的子窗口部件时才有效。
您可以修改它以使其工作如下:
我稍微修改了你的样本:
<zk>
<script><![CDATA[
zk.afterLoad('zul.db', function () {
var _xRenderer = {};
zk.override(zul.db.Renderer, _xRenderer, {
titleHTML: function (wgt, out, localizedSymbols) {
_xRenderer.titleHTML.apply(this, arguments); //call the original method
var uuid = wgt.uuid,
view = wgt._view,
text = wgt.getZclass() + '-ctrler';
if(view == 'day') {
out.push('<button id="', uuid, '-today" class="', text, '"',
' onClick="var cal = zk.Widget.$(\'$', wgt.parent.id, '\')._pop; cal._value = null; cal._setTime();"',
' >', ' today', '</button>');
}
out.push('<button id="', uuid, '-clear" class="', text, '"',
' onClick="clearDatebox(this)"',
' >', ' clear', '</button>');
}
});
});
function clearDatebox (btn) {
var id = jq('.z-datebox-pp')[0].id.replace('-pp', ''),
dbx = zk.Widget.$('#' + id);
dbx.getInputNode().value = '';
dbx.updateChange_();
}
]]></script>
<datebox id="db" ></datebox>
</zk>
答案 1 :(得分:1)
我修改了以上链接代码然后它正在运行。
版本 - zk 6.5.3
<zk>
<script><![CDATA[
zk.afterLoad('zul.db', function () {
var _xRenderer = {};
zk.override(zul.db.Renderer, _xRenderer, {
titleHTML: function (wgt, out, localizedSymbols) {
_xRenderer.titleHTML.apply(this, arguments); //call the original method
var uuid = wgt.uuid,
view = wgt._view,
text = wgt.getZclass() + '-ctrler';
if(view == 'day') {
out.push('<button id="', uuid, '-today" class="', text, '"',
' onClick="var cal = zk.Widget.$(\'$', wgt.parent.id, '\')._pop; cal._value = null; cal._setTime();"',
' >', ' today', '</button>');
}
out.push('<button id="', uuid, '-clear" class="', text, '"',
' onClick="clearDatebox(this)"',
' >', ' clear', '</button>');
}
});
});
function clearDatebox (btn) {
var str = btn.id;
var res = str.substring(3,4);
if(res==0){
var id = jq('.z-datebox-inp')[res].id,
dbx = zk.Widget.$('#' + id);
dbx.getInputNode().value = '';
dbx.updateChange_();
}else{
var id = jq('.z-datebox-inp')[res/2].id,
dbx = zk.Widget.$('#' + id);
dbx.getInputNode().value = '';
dbx.updateChange_();
}
}
]]></script>
<datebox id="db" ></datebox>
<datebox id="db1" ></datebox>
<datebox id="db2" ></datebox>
<datebox id="db3" ></datebox>
</zk>
或
更改此方法。
function clearDatebox (btn) {
var d=jq('.z-datebox-pp').length-1;
var id = jq('.z-datebox-pp')[d].id.replace('-pp', ''),
dbx = zk.Widget.$('#' + id);
dbx.getInputNode().value = '';
dbx.updateChange_();
}
这里的zk版本7.0代码
<zk>
<script><![CDATA[
zk.afterLoad('zul.db', function () {
var _xRenderer = {};
zk.override(zul.db.Renderer, _xRenderer, {
titleHTML: function (wgt, out, localizedSymbols) {
_xRenderer.titleHTML.apply(this, arguments); //call the original method
var uuid = wgt.uuid,
view = wgt._view,
text = wgt.getZclass() + '-ctrler';
if(view == 'day') {
out.push('<button id="', uuid, '-today" class="', text, '"',
' onClick="setDatebox(this)"',
' >', ' today', '</button>');
}
out.push('<button id="', uuid, '-clear" class="', text, '"',
' onClick="clearDatebox(this)"',
' >', ' clear', '</button>');
}
});
});
function clearDatebox (btn) {
var str = btn.id;
var res = str.substring(3,4);
if(res==0){
document.getElementById(jq('.z-datebox-input')[res].id).value='';
}else{
document.getElementById(jq('.z-datebox-input')[res/2].id).value='';
}
}
function setDatebox (btn) {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm}
today = mm+'/'+dd+'/'+yyyy;
var str = btn.id;
var res = str.substring(3,4);
if(res==0){
document.getElementById(jq('.z-datebox-input')[res].id).value=today;
}else{
document.getElementById(jq('.z-datebox-input')[res/2].id).value=today;
}
}
]]></script>
<datebox id="db" ></datebox>
<datebox id="db1" ></datebox>
<datebox id="db2" ></datebox>
<datebox id="db3" ></datebox>
</zk>