200分求助,还有100分在另外一个帖子里拿,关于c#webbrowser调用一个页面js日期选择框方法

神奇的章鱼哥 2016-11-09 09:48:29

目的是达到调用日期选择框,选择日期,他文本里不能输,只能在弹出框里选:
网页已经打开,我想选择2009-03-30的话,c#里该怎么写?
js代码看到是这样:

function Calender() {
this._shell = create("div", "main dt_pnl");
//this._shell.id = $utils.shell.nextID();
document.body.appendChild(this._shell);
$utils.shell.showCell(this._shell, false);

// 上中下三行
var pnl_rows = $vf.fillCell(this._shell, [ 24, 120, 24 ],
[ 120 ], [],[], "pnl_cell");
var cls = [ "dt_hd", "pnl_cell dt_body", "dt_foot" ];
for ( var i = 0; i < pnl_rows.length; i++) {
pnl_rows[i][0].className = cls[i];
}

// 表头
this.hds = $vf.fillCell(pnl_rows[0][0], [ 18 ], [ 24, 40, 12,
30, 16, 18 ], [], [], "pnl_cell")[0];
cls = [ "dt_hd_left", "dt_hd_y", "dt_hd_ys", "dt_hd_m", "dt_hd_ms",
"dt_hd_right" ];
var type_t = [ "hd_left", "hd_y", "hd_y", "hd_m", "hd_m", "hd_right" ];
for ( var j = 0; j < this.hds.length; j++) {
this.hds[j].className = "dt_hd_cell " + cls[j];
this.hds[j]._t = type_t[j];
}

// 表体
this.bodys = $vf.fillCell(pnl_rows[1][0], [ 22, 20, 20, 20, 20,
20, 20 ], [ 20, 20, 20, 20, 20, 20, 20 ], [], [], "dt_cell");
for ( var k = 0; k < 7; k++) {
this.bodys[0][k].innerHTML = this._const[k];
$utils.style.setStyle(this.bodys[k][0],"color:red");
$utils.style.setStyle(this.bodys[k][6],"color:red");
//this.bodys[k][0].style.color = this.bodys[k][6].style.color = "red";
}

// 表尾
var btn1, btn = [ 'yes', 'today', 'cancel' ];
for ( var p = 0; p < 3; p++) {
btn1 = $utils.fn.create("div", 'dt_btn');
btn1.innerHTML = this._const[p + 9];
btn1._t = btn[p];
pnl_rows[2][0].appendChild(btn1);
}
this.days = new SelfMap();
// 本日
var cdate = new Date();
this._cy = cdate.getFullYear();
this._cm = cdate.getMonth();
this._cd = cdate.getDate();
this._evts = new EventCell();

this._evts.add($utils.events.regBindEvent(this._shell, "click",this, this.select1));
this._evts.add($utils.events.regBindEvent(this._shell, "dblclick", this, this.select2));
new Drag().init(this._shell, this.hds[2], this.hds[4]);// pnl_rows[0][0]
}

Calender.prototype = {
_menu_m:null,
_menu_y:null,
_old_cell : null,
_td_cell : null,
_y_cell : null,// 年
_m_cell : null,// 月

_y : null,
_m : null,
_d : null,

_max_d : null,

_cy : null,// 今年
_cm : null,// 本月
_cd : null,// 今日
_from : 1901,
_to : 2100,
// "日", "一", "二", "三", "四", "五", "六", "年", "月", "确认", "今日", "取消"
_const : [ "\u65E5", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94",
"\u516D", "\u5E74", "\u6708", "\u786E\u8BA4", "\u4ECA\u65E5",
"\u53D6\u6D88" ],

show : function(comp, value) {
this.comp = comp;
this.setValue(value ? value : new Date());
$utils.shell.showWindow(this, comp.getShell(), true, "right");
},

/**
* ok
*
* @param value
* @returns
*/
setValue : function(value, verify) {
// 修改y,m,d
if (value && (typeof (value) == 'string')) {
try {
value = $utils.fmt.toDate(value, 'date', verify);
} catch (e) {
value = null;
}
}
value = value ? value : new Date();
var y1 = value.getFullYear();
var m1 = value.getMonth();

var day = value.getDate();
if ((y1 != this._y) || (m1 != this._m)) {
this._y = y1;
this._m = m1;
this._d=day;
// this.repaint();
}
this.changeMonth(m1, true);
this.changeDay(day);
},
showMonth : function(e) {
$utils.events.cancelEvent(e, true);
if (!this._menu_m) {
var p1 = new SelfMap();
//p1.put("popup", "1");
this.listM = new SelfList(p1, "dt_m_list");
// this.listM.hide();
for ( var i = 0; i < 12; i++) {
this.listM.addItem(i, (i + 1) + '');
}
//this.listM.getShell().style.height=(12*18)+"px";
$utils.style.setStyle(this.listM.getShell(), "height:"+(12*18)+"px");
// document.body.appendChild(this.listM.getShell());
this.listM.addChangedListen(this);
this._menu_m=new PopupMenu(this.listM, this.hds[3], 'down');
}
if ($utils.shell.isCellShow(this._menu_m.getShell())){
$utils.menu.hideMenu(this._menu_m);
}else{
this.listM.setValue(this._m,true);
$utils.menu.showMenu(this._menu_m);
}
//SelfComboBox.prototype.showLinkMenu(this.hds[3], this.listM, this._m, true);
},

showYears : function(e) {
$utils.events.cancelEvent(e, true);
if (!this._menu_y) {
var p1 = new SelfMap();
this.listY = new SelfList(p1, "dt_y_list");
for ( var i = this._from; i <= this._to; i++) {
this.listY.addItem(i, i + '');
}
// document.body.appendChild(this.listY.getShell());
// setStyle(this.listY.getShell(), "height:"+(12*18)+"px");
$utils.style.setStyle(this.listY.getShell(), "height:"+(12*18)+"px");
this.listY.addChangedListen(this);
this._menu_y=new PopupMenu(this.listY, this.hds[1], 'down');
}
if ($utils.shell.isCellShow(this._menu_y.getShell())){
$utils.menu.hideMenu(this._menu_y);
}else{
this.listY.setValue(this._y,true);
$utils.menu.showMenu(this._menu_y);
}
// $vf.showLinkMenu(this.hds[1], this.listY, this._y,
// true);
},

changeYear : function(y, draw) {
this._y = y;
this.hds[1].innerHTML = y + this._const[7];
if (draw) {
this.repaint();
}
},
changeMonth : function(m, draw) {
if (m < 0) {
this._m = 11;
this._y--;
} else if (m > 11) {
this._m = 0;
this._y++;
} else {
this._m = m;
}
this.hds[3].innerHTML = (this._m + 1) + this._const[8];
this.changeYear(this._y, false);
this.repaint();
},
changeDay : function(day) {
var d1 = new Date(this._y, this._m + 1, 0);
if (day > d1.getDate()) {
day = d1.getDate();
}
if (this._old_cell) {
// 以前选择的日期
$utils.style.setStyle(this._old_cell, "background-color:"+((this._old_cell._t == '_a') ? 'yellow'
: '#ffffff'));
}
this._old_cell = this.days.get('d' + day);
// 加亮当前选中的单元
$utils.style.setStyle(this._old_cell, "background-color:#BFDDDD");
// 加圆角当前选中的单元
$utils.style.setStyle(this._old_cell, "border-radius:2px");
//this._old_cell.style.backgroundColor = "#99BBE8";
this._d = day;
},
repaint : function() {
// 用当月第一天在一周中的日期值
var date = new Date(this._y, this._m, 1);
var firstDay = date.getUTCDay();
// 月份天数
this._max_d = new Date(this._y, this._m + 1, 0).getDate();
var daily = 1;
var isday = false;
this.days.clear();
for ( var i = 1; i < 7; i++) {
for ( var j = 0; j < 7; j++) {
var cell = this.bodys[i][j];
cell.className = "dt_cell";
if ((firstDay == 6) || (j == (firstDay + 1))) {
isday = true;
}
if (isday && (daily <= this._max_d)) {
this.days.put("d" + daily, cell);
cell.innerHTML = daily++;
cell._t = "_d";
$utils.style.setStyle(cell, "cursor:pointer;");
} else {
cell.innerHTML = " ";
cell._t = "";
}
$utils.style.setStyle(cell, "border:none;background-color:white;color:"+(((j == 0) || (j == 6)) ? "red" : "black"));
}
}
if ((this._y == this._cy) && (this._m == this._cm)) {
var cc = this.days.get("d" + this._cd);
cc._t = "_a";
$utils.style.setStyle(cc, "background-color:yellow");
$utils.style.setStyle(cc, "border:0px solid red;");
}
this.changeDay(this._d);

},
close : function() {
this.comp = null;
if (this._menu_m){
$utils.menu.hideMenu(this._menu_m);
}
if (this._menu_y){
$utils.menu.hideMenu(this._menu_y);
}
$utils.shell.closeWindow(this);
},

today : function() {
this.setValue(new Date(), true);
},
isModal : function() {
return true;
},
getShell : function() {
return this._shell;
},
/**
* 接受年度或月份的改变
*
* @param src
* @returns
*/
acceptChanged : function(src) {
var v = $utils.fn.getInt(src.getValue());
if (v > 100) {
this.changeYear(v, true);
} else {
this.changeMonth(v);
}
},
/**
* 点击某日做作的选择改变
*
* @param e
* @returns
*/
select2 : function(e) {
e = e || window.event;
var cell = e.target || e.srcElement;
if ((cell._t == '_d') || (cell._t == '_a')) {
this.changeDay($utils.shell.getLableText(cell));
this.select();
}else if (cell._t=='today'){
this.select();
}
},
/**
* 确认操作或双击作出的响应
*
* @returns
*/
select : function() {
if (this.comp) {
this.comp
.setValue(this._y + "-" + (this._m + 1) + "-" + this._d);
}
this.close();
},

// "hd_left","hd_y","hd_y","hd_m","hd_m","hd_right"
select1 : function(e) {
var src = e.target || e.srcElement;
if (!!(src._t)) {
switch (src._t) {
case "_a":
case "_d":
// 选中某日
this.changeDay($utils.fn.getInt($utils.shell.getLableText(src)));
break;
case "hd_left":
this.changeMonth(this._m - 1);
break;
case "hd_right":
this.changeMonth(this._m + 1);
break;
case "hd_y":
// 点击年
this.showYears(e);
break;
case "hd_m":
// 点击年月
this.showMonth(e);
break;
case "yes":
// 确认
this.select();
break;
case "today":
// 今日
this.setValue(new Date(), true);
break;
case "cancel":
// 取消
this.close();
break;
default:
break;
}
}
}
};
$utils.fmt.showCalender=function(comp, value){
if (this._calender == null) {
this._calender = new Calender();
}
this._calender.show(comp, value);
};

...全文
131 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
beautiful_melody 2016-11-10
  • 打赏
  • 举报
回复
好像.net c#有现成的日历控件吧,怎么舍近求远整个js的呢
EnForGrass 2016-11-10
  • 打赏
  • 举报
回复
你应该去看看日期控件是什么?jquery插件里的?去看看对应的源码,怎么用js去赋值
神奇的章鱼哥 2016-11-09
  • 打赏
  • 举报
回复
还有100分在这里拿 http://bbs.csdn.net/topics/392045290

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧