| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6936 人关注过本帖
标题:如何用vb实现网页中的javascript的控件操作?
只看楼主 加入收藏
享誉
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-10-10
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
如何用vb实现网页中的javascript的控件操作?
有一个局域网,登录后,进入一个有javascript的grid控件网页,很难进行分析,操作就进行不下去了。请问如何用vb实现网页中的javascript的控件操作?
搜索更多相关主题的帖子: javascript 如何 局域网 
2012-10-10 15:24
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:14 
---------------长度超过 255 的JS 代码,这样插入---------------------
    Dim js As String
   
    Dim obj As HTMLDocument
    Set obj = pDisp.Document
   
    '插入 JS 函数,JS 函数写在 RES 文件中
    obj.parentWindow.execScript LoadResString(101)      '选择
    obj.parentWindow.execScript LoadResString(102)      '清除选择
    'obj.parentWindow.execScript LoadResString(103)      '填姓名,身份证
   
    obj.parentWindow.execScript "function setxm(id1,id2){document.vsub.n.value=id1;document.vsub.num.value=id2;}"
   
    DoEvents
   
-----------执行,可以简单的这样用---------------
    js = "javascript:clerum();setum(6);"
    WebBrowser1.Navigate js
    DoEvents
-------------------------

授人于鱼,不如授人于渔
早已停用QQ了
2012-10-11 08:19
享誉
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-10-10
收藏
得分:0 
我在VBA中时这样做的。
[local]2[/local]
Private Sub CommandButton1_Click()
Dim x As Integer
Dim Uname As String
Dim Upw As String
x = Sheets("sheet2").Range("A65536").End(3).Row
For i = 1 To x
With CreateObject("InternetExplorer.Application")
Uname = Sheets("sheet2").Cells(i, 1).Value
Upw = Sheets("sheet2").Cells(i, 2).Value
.Visible = True
.Navigate "http://172.16.1.242:7001/kaoshi.do"
Do Until .Readystate = 4
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:02"))
If .locationname = "安全监督与管理系统" Then
 .Document.Forms(0).All.tags("img")(1).Click
Else
'.Document.Forms(0).All("username").Value = Uname
'.Document.Forms(0).All("password").Value = Upw
'.Document.Forms(0).All("login_img").Click
.Document.Forms(0).All("j_username").Value = Uname
.Document.Forms(0).All("j_password").Value = Upw
.Document.Forms(0).All.tags("input")(4).Click
.Document.Forms(0).All.tags("img")(5).Click


Application.Wait (Now + TimeValue("0:00:02"))

.Document.Forms(0).getelementsbytagname("primarykey").Click
.Document.Forms(0).All.tags("button")(2).Click

End If
Application.Wait (Now + TimeValue("0:00:05"))
.Quit
End With
Next
MsgBox "Ok"
End Sub

红色代码前是自动登录代码,已经完成。
登录后进入选择考试界面。

这个是源代码:

<HTML>
<HEAD>
<TITLE>考试计划基本信息表查询</TITLE>
<link rel="stylesheet" type="text/css" href="http://172.16.1.242:7001/skins/default/css/skin.css">
<link rel="stylesheet" type="text/css" href="/css/saf/ks/DA_comm.css">
<script language="javascript" src="http://172.16.1.242:7001/skins/default/js/flexgrid.js"></script>
<link rel="stylesheet" type="text/css" href="http://172.16.1.242:7001/skins/default/css/flexgrid.css">
<link rel="stylesheet" type="text/css" href="http://172.16.1.242:7001/skins/default/css/date.css">
<script language="javascript" src="http://172.16.1.242:7001/skins/default/js/calendar.js"></script>
<script language="javascript" src="/js/saf/ks/zxks/DA_Service.js" /></script>
<script language="javascript" src="/js/saf/ks/DA_publicfunction.js" /></script>

</HEAD>
<BODY topmargin="10px">

<div class="examtitle1"><img src="/images/saf/ks/title.gif"> 在线考试</div>

<TABLE class="tblList" id="tblMain"  width="100%" height="" cellpadding="0">
<TBODY>
<TR>
<TD vAlign="top" height="15px">
<TABLE width="100%" background="http://172.16.1.242:7001/skins/default/images/title_bgright.gif" cellpadding="0" cellspacing="0">
<TR>
<TD vAlign="bottom">
<TABLE class="tblHead" id="tblHead" background="http://172.16.1.242:7001/skins/default/images/title_bgright.gif" cellpadding="0">
<TR>
<TD><IMG src="http://172.16.1.242:7001/skins/default/images/title_left.gif" border="0"></TD>
<TD class="tdHeadlineText" id="tdHeadlineText" vAlign="bottom" background="http://172.16.1.242:7001/skins/default/images/title_bgleft.gif" nowrap>

</TD>
<TD><IMG src="http://172.16.1.242:7001/skins/default/images/title_right.gif" border="0"></TD>
</TR>
</TABLE></TD>
<TD style="TEXT-ALIGN: right" width="56%" nowrap id="TagContainerButtonArea1">
</TD>
 </TR>
</TABLE>
<TABLE class="tblHeadline" id="tblHeadline" width="100%" background="http://172.16.1.242:7001/skins/default/images/skin_top_bg.gif" cellpadding="0">
<TR>
<TD class="tdHeadline"><IMG src="http://172.16.1.242:7001/skins/default/images/skin_top_left.gif"></TD>
<TD class="tdHeadline" vAlign="bottom" align="right"><IMG src="http://172.16.1.242:7001/skins/default/images/skin_top_right.gif" border="0"></TD>
</TR>
 </TABLE>
 </TD></TR>
 <TR><TD>
<TABLE class="tblWorkArea" id="tblWorkArea" width="100%" height="100%" cellpadding="0">
<TR>
<TD class="tdMargin3px" background="http://172.16.1.242:7001/skins/default/images/skin_right.gif"></TD>
<TD class="tdWorkArea" id="tdWorkArea" valign="top" height="100%">







<form name="frmList" method="post" action="personexamplanquery_page_init.cmd?operatetype=current&clear=true&flag=1&examno=1201194261000001"><div><input type="hidden" name="org.sotower.web.taglib.util.token" value="7eb46425ebb2be3d09fe4a39815dd841"></div><input type="hidden" name="sysFunctionId" value="">
<table id="tblSearch">
<tr>
    <td>考试名称:<input type="text" name="titleSearch" maxlength="100" size="12" value="" class="searchText"></td>
    <td>考试地点:<input type="text" name="addressSearch" maxlength="100" size="12" value="" class="searchText"></td>
    <td colspan="2">考试开始时间:<input size="16" class="date_input" value="" onchange="start_datedd.setHidDateValInCalendar('yyyy-MM-dd');" readonly="readonly" ondblclick="javascript:this.value='';"name="start_dateSearch"><button  hideFocus="true" UNSELECTABLE="on" title="日历" class="date_button" onclick="start_datedd.showDate();">6</button><div id="start_datedd" class="date" style="display:none;overflow:hidden;position:absolute;z-index:10;" onpropertychange="start_datedd.doUpDown();"><div><table border="0" cellpadding="1" cellspacing="1" class="date_table"><tr><td>
<div class="dateadjust" style="width:80px;"><div style="position:relative;left:47;top:2;">
<button style="left:9;top:-1;height:10;" hideFocus="true" onclick="start_datedd._uper(this);start_datedd.changeYearAndMonth(this.parentElement.nextSibling.value);"  onmousedown="start_datedd._conti_uper(this);start_datedd.changeYearAndMonth(this.parentElement.nextSibling.value);" onmouseout="start_datedd._stop_inch();" onmouseup="start_datedd._stop_inch();">5</button>
<button style="left:9;top: 8;height:10;" hideFocus="true" onclick="start_datedd._downer(this);start_datedd.changeYearAndMonth(this.parentElement.nextSibling.value);"  onmousedown="start_datedd._conti_downer(this);" onmouseout="start_datedd._stop_inch();" onmouseup="start_datedd._stop_inch();">6</button></div>
<input type=text style="padding-top:2;position:relative;left:2;" value="2012" onblur="start_datedd.doYearBlur(this);" conf="1,1900,2100,"></div></td>
<td><span  class="month" style="height:19;left:3;"><select size="1" onchange="start_datedd.changeYearAndMonth(null,this.options[this.selectedIndex].value)">
<option value="1">一月</option>
<option value="2">二月</option>
<option value="3">三月</option>
<option value="4">四月</option>
<option value="5">五月</option>
<option value="6">六月</option>
<option value="7">七月</option>
<option value="8">八月</option>
<option value="9">九月</option>
<option value="10"selected>十月</option>
<option value="11">十一月</option>
<option value="12">十二月</option>
</select></span></td></tr></table></div>
<div align=center></div>
<iframe frameborder=0 style="width:100%;height:103%;top:0;left:0;position:absolute;z-index:-1;"></iframe></div>
<script language="javascript">var start_datedd=new Calendar("start_datedd"); start_datedd.init("start_datedd",2012,10,9,14,47,8,"yyyy-MM-dd","yyyy-MM-dd"); </script>

            &nbsp;至&nbsp;<input size="16" class="date_input" value="" onchange="end_datedd.setHidDateValInCalendar('yyyy-MM-dd');" readonly="readonly" ondblclick="javascript:this.value='';"name="end_dateSearch"><button  hideFocus="true" UNSELECTABLE="on" title="日历" class="date_button" onclick="end_datedd.showDate();">6</button><div id="end_datedd" class="date" style="display:none;overflow:hidden;position:absolute;z-index:10;" onpropertychange="end_datedd.doUpDown();"><div><table border="0" cellpadding="1" cellspacing="1" class="date_table"><tr><td>
<div class="dateadjust" style="width:80px;"><div style="position:relative;left:47;top:2;">
<button style="left:9;top:-1;height:10;" hideFocus="true" onclick="end_datedd._uper(this);end_datedd.changeYearAndMonth(this.parentElement.nextSibling.value);"  onmousedown="end_datedd._conti_uper(this);end_datedd.changeYearAndMonth(this.parentElement.nextSibling.value);" onmouseout="end_datedd._stop_inch();" onmouseup="end_datedd._stop_inch();">5</button>
<button style="left:9;top: 8;height:10;" hideFocus="true" onclick="end_datedd._downer(this);end_datedd.changeYearAndMonth(this.parentElement.nextSibling.value);"  onmousedown="end_datedd._conti_downer(this);" onmouseout="end_datedd._stop_inch();" onmouseup="end_datedd._stop_inch();">6</button></div>
<input type=text style="padding-top:2;position:relative;left:2;" value="2012" onblur="end_datedd.doYearBlur(this);" conf="1,1900,2100,"></div></td>
<td><span  class="month" style="height:19;left:3;"><select size="1" onchange="end_datedd.changeYearAndMonth(null,this.options[this.selectedIndex].value)">
<option value="1">一月</option>
<option value="2">二月</option>
<option value="3">三月</option>
<option value="4">四月</option>
<option value="5">五月</option>
<option value="6">六月</option>
<option value="7">七月</option>
<option value="8">八月</option>
<option value="9">九月</option>
<option value="10"selected>十月</option>
<option value="11">十一月</option>
<option value="12">十二月</option>
</select></span></td></tr></table></div>
<div align=center></div>
<iframe frameborder=0 style="width:100%;height:103%;top:0;left:0;position:absolute;z-index:-1;"></iframe></div>
<script language="javascript">var end_datedd=new Calendar("end_datedd"); end_datedd.init("end_datedd",2012,10,9,14,47,8,"yyyy-MM-dd","yyyy-MM-dd"); </script>
</td>
    <td><input name="chaxun" type="image" src="http://172.16.1.242:7001/skins/default/images/search.gif" onClick="javascript:if(!checkSearch()) return false;;this.form.action='personexamplanquery_page_init.cmd?operatetype=current&clear=true&flag=1&examno=1201194261000001';document.all('org.sotower.web.taglib.util.GRIDINFOPRIMARY').value=null;document.all('org.sotower.web.taglib.util.RESETPAGEINDEX').value='true'" style="cursor: hand;"></td>
    </tr><input type="hidden" name="org.sotower.web.taglib.util.SEARCHINFOCOLUMNS" value="titleSearch:DA_EXAMPLAN.TITLE:java.lang.String:=:false:false:;addressSearch:DA_EXAMPLAN.ADDRESS:java.lang.String:=:false:false:;start_dateSearch:DA_EXAMPLAN.START_DATE:java.lang.String:=:false:false:;end_dateSearch:DA_EXAMPLAN.END_DATE:java.lang.String:=:false:false:">

</table>
<script language="javascript">
var grid = new GRID();
var grid_jsonstr={"ColumnNames":["primaryKey","mainplan_id","planlevel","title","address"],"GRIDINFO":{"increaseIndex":"false","height":"222","hidden":[{"value":"","name":"org.sotower.web.taglib.util.GRIDINFOSORTTYPE"},{"value":"","name":"org.sotower.web.taglib.util.GRIDINFOSORTNAME"},{"value":"","name":"org.sotower.web.taglib.util.GRIDINFOPRIMARY"},{"value":"DA_EXAMPLAN.PLAN_ID;DA_EXAMPLAN.MAINPLAN_ID;DA_EXAMPLAN.PLANLEVEL;DA_EXAMPLAN.TITLE;DA_EXAMPLAN.ADDRESS","name":"org.sotower.web.taglib.util.GRIDINFOCOLUMNS"}],"isWrap":"false","hasLeft":"true","name":"grid","hasSum":"false"},"TabHead":{"rows":[{"cols":[{"width":"40","text":"选择","sortName":"DA_EXAMPLAN.PLAN_ID","style":"","sortType":"ASC","enableCheckAll":"true","format":"","canSort":"false"},{"width":"100","text":"主计划ID","sortName":"DA_EXAMPLAN.MAINPLAN_ID","style":"display:none","sortType":"ASC","enableCheckAll":"false","canSort":"true"},{"width":"100","text":"补考级别","sortName":"DA_EXAMPLAN.PLANLEVEL","style":"display:none","sortType":"ASC","enableCheckAll":"false","canSort":"true"},{"width":"100%","text":"考试名称","sortName":"DA_EXAMPLAN.TITLE","style":"text-align:left;","sortType":"ASC","enableCheckAll":"false","canSort":"true"},{"width":"150","text":"考试地点","sortName":"DA_EXAMPLAN.ADDRESS","style":"text-align:left;","sortType":"ASC","enableCheckAll":"false","canSort":"true"}]}]},"TabSum":{"rows":[{"cols":[{"text":"","width":"40"},{"text":"","width":"100","style":"display:none"},{"text":"","width":"100","style":"display:none"},{"text":"","width":"100%","style":"text-align:left;"},{"text":"","width":"150","style":"text-align:left;"}]}]},"TabTi":{"rows":[{"cols":[{"width":"40","eventString":"","coltype":"checkbox","disabled":"false","name":"primaryKey"},{"value":"","width":"100","eventString":"","coltype":"flex","style":"display:none"},{"value":"","width":"100","eventString":"","coltype":"flex","style":"display:none"},{"value":"","width":"100%","eventString":"","coltype":"flex","style":"text-align:left;"},{"value":"","width":"150","eventString":"","coltype":"flex","style":"text-align:left;"}]},{"cols":[{"value":"2c9081203991d585013a43236e8c09c9","checked":""},{"value":"2c9081203991d585013a43236e8c09c9","title":"2c9081203991d585013a43236e8c09c9"},{"value":"0","title":"0"},{"value":"安规测试1","title":"安规测试1"},{"value":"","title":""}]}]}};
grid.outHtml(grid_jsonstr,"http://172.16.1.242:7001/skins/default/js","grid");
grid.setSubmit(false);
function showGrid(){
this.init("grid");

}
grid.show = showGrid;
</script>

<table border="0" cellpadding="0" cellspacing="1" class="datactrl"><tr>
<td><input type="button" value="&ccedil;" title="上一页" hidefocus="true"></td>

<td><input type="button" value="è" title="下一页" hidefocus="true"></td>


<td style="font-size:9pt;border:0px;">共 1 页 第 1 页&nbsp;共 1 条,从 1 条到 1 条</td>
</tr>
</table>
<input type="hidden" name="org.sotower.web.taglib.util.PAGEPOLITPAGESIZE" value="10">
<input type="hidden" name="org.sotower.web.taglib.util.PAGEPOLITCURRENTPAGEINDEX" value="1">
<input type="hidden" name="org.sotower.web.taglib.util.RESETPAGEINDEX" value="false">

</form>
</TD>
<TD class="tdMargin3px" background="http://172.16.1.242:7001/skins/default/images/skin_left.gif"></TD></TR></TABLE>
 </TD></TR>
 <TR><TD height=5>
<TABLE class="tblFoot" id="tblFoot" width="100%" background="http://172.16.1.242:7001/skins/default/images/skin_bottom_bg.gif" cellpadding="0">
<TR>
<TD class="tdFootLeft"><IMG src="http://172.16.1.242:7001/skins/default/images/skin_bottom_left.gif"></TD>
<TD class="tdFootRight"><IMG src="http://172.16.1.242:7001/skins/default/images/skin_bottom_right.gif"></TD>
 </TR>
</TABLE></TD>
</TR>
</TABLE>
<script language="javascript">
var TagContainerButtonArea1=document.all("TagContainerButtonArea1");
if(TagContainerButtonArea1!=null && TagContainerButtonArea1.tagName=="TD")
TagContainerButtonArea1.innerHTML='<button  onclick="forSimpleDetail()" onmouseover="this.className=\'advbutton-over\';" onmouseout="this.className=\'advbutton\';" class="advbutton">详细信息</button>&nbsp;<button  onclick="checkIp()" onmouseover="this.className=\'advbutton-over\';" onmouseout="this.className=\'advbutton\';" class="advbutton">检验IP地址</button>&nbsp;<button  onclick="startExam()" onmouseover="this.className=\'advbutton-over\';" onmouseout="this.className=\'advbutton\';" class="advbutton">进入考试</button>&nbsp;';
</script>

<script language="javascript">
grid.show();
  function validateDate(){
    var queryDateStart = document.getElementById("start_dateSearch").value;
    var queryDateEnd = document.getElementById("end_dateSearch").value;
    if(queryDateStart!="" && queryDateEnd!="" && queryDateStart>queryDateEnd){
        alert("查询结束时间不能小于查询起始时间!");
        return false;
    }
    return true;
}
//监听回车事件
function document.onkeydown()
{
    if(event.keyCode == "13")
    {
        return checkSearch();
    }
}

//检验查询条件
function checkSearch()
{
    var value = document.getElementById("titleSearch").value;
    var value1 = document.getElementById("addressSearch").value;
    if( CheckSearch(value) || CheckSearch(value1))
    {
        return false;
    }
    if(!validateDate())
    {
        return false;
    }
    return true;
}
function forSimpleDetail(){
  if(!getSelect()) return;
  var line = grid.getCheckLineNo();
  var primaryKey=grid.getCellValue(line, 1);
  window.open ('daexamplan.cmd?method=simpleDetail&primaryKey='+primaryKey+'&operatetype=current', '', 'height=400, width=600, top=10, left=60, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no');        
}

function startExam(){
    if(!getSelect()) return;
    if(!window.confirm("您确定要进入考试吗?")){
        return;
    }
    var line = grid.getCheckLineNo();
      var planId=grid.getCellValue(line, 1);
    var url = "examonline.cmd?method=examStart&examPlanId="+planId+"&wstime="+(new Date()).valueOf();
    window.showModalDialog(url,window,"dialogTop:0;dialogWidth:"+(window.screen.availWidth)+"px;DialogHeight="+(window.screen.availHeight)+"px;help=0;center=1;status:no;scroll=1");
    window.location = window.location;
}
function checkIp()
{
    if(!getSelect()) return;
    var line = grid.getCheckLineNo();
      var planId=grid.getCellValue(line, 1);
    var service = new Service();
    service.serviceUrl = "/examonline.cmd";
    service.serviceParam = "method=checkIp&planId="+planId;

    var result = service.send(planId);
   
    if(result == "1")
    {
        alert("您的IP地址可以参加考试!");
    }
    else
    {
        alert("你的IP地址不合法,不能参加考试!请换台机器或联系管理员!");
    }
}
function viewExam(){
    if(!getSelect()) return;
    var line = grid.getCheckLineNo();
      var planId=grid.getCellValue(line, 1);

      if(grid.getCellValue(line, 7) == "未阅卷")
      {
          alert("试卷未批阅,不能浏览!");
          return;
      }

    var url ="/dayj.cmd?method=examCS&examPlanId="+planId+"&toPage=own"+"&wstime="+(new Date()).valueOf();
   
    window.showModalDialog(url,window,"dialogTop:0;dialogWidth:"+(window.screen.availWidth)+"px;DialogHeight="+(window.screen.availHeight)+"px;help=0;center=1;status:no;scroll=1");
}
function forDetail(){
  if(!getSelect()) return;
  document.forms[0].action ="daexamplan.cmd?method=detail";   
  document.forms[0].submit();   
}
function forDelete(){
  if(!getDelete()) return;
  document.forms[0].action ="daexamplan.cmd?method=delete";   
  document.forms[0].submit();   
}
function getSelect(){
  var sel=grid.getCheckLine();
  if(sel==""){
    alert("请选择一条记录!");
    return false;
  }
  var obj=sel.split(",");  
  if(obj.length*1>1){
    alert("请选择一条记录!");
    return false;
  }  
  return true;
}
function getDelete(){
  var sel=grid.getCheckLine();
  if(sel==""){
    alert("请选择要删除的记录!");
    return false;
  }
  if (!confirm("真的要删除选中的记录吗?此操作不能恢复!")) {
            return false;
            }  
  return true;
}
</script>
自动登录考试系统.rar (13.33 KB)


[ 本帖最后由 享誉 于 2012-10-11 10:03 编辑 ]
2012-10-11 09:42
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:0 
看了一下你红色代码,建议如下:
你写一个 JS 的函数,这个函数,就只负责在网页内做你想要做的事。
然后载入这个网页后,把这个 JS 函数插入到 页面 中去,方法看我的代码。
然后再 要做这些事时,再调用这个 JS 函数。调用方式见我的代码。

用 VB 来分析源代码,找到指定的 对象,再执行指定的操作,实在是很烦很烦。
以前我一直就是用这个方法,结果烦透了。然后再去找 JS 的方法,比光用 VB 的代码 好看多了,也灵活一些了。
除下无法有返回值后,其它功能都可以实现。必竟 JS 就是操作 网页的。

授人于鱼,不如授人于渔
早已停用QQ了
2012-10-11 11:42
享誉
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2012-10-10
收藏
得分:0 
不好意思哦,这个js我没有学过。
2012-10-11 13:28
快速回复:如何用vb实现网页中的javascript的控件操作?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018112 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved