有元素ID号,但无法获取网页元素 <tr id="J_Post">
<!-- id="pt:postFee" -->
<td class="first-col">运送方式:</td>
<td class="consignment">
<span class="h">*</span> 
<input type="hidden" id="shipCategory" value="0"/>
<input type="hidden" id="sellerId" name="userId" value="82884615" />
<input type="hidden" id="codPostageId"  />
<div class="general-box J_General">
<ul data-order="b_7651003549" class="J_PromoCombo">
<li>
     <input class="ah:postageOption buyItem:post J_General_Ra" type="radio" name="_shipping_option" value="1" id="shipping1"  />
     <label for="shipping1">平邮:<span id="postfee1">10.00</span></label>
</li>
<li>
     <input class="ah:postageOption buyItem:post J_General_Ra" type="radio" name="_shipping_option" value="2" id="shipping2" >
     <label for="shipping2">快递:<span id="postfee2">15.00</span></label>
</li>
<li>
     <input class="ah:postageOption buyItem:post J_General_Ra" type="radio" name="_shipping_option" value="7" id="shipping7" >
     <label for="shipping7">EMS:<span id="postfee7">20.00</span></label>
</li>
</ul>
</div>

<input type="hidden" id="shippingHidden" name="_fm.g._0.sh" value="" />
     </td>
</tr>
如果网页仅仅只有上面一段代码的话是可以获取的,比如“快递”的ID号=shipping2,
我可以写代码进行赋值webBrowser1.Document.GetElementById("shipping2").SetAttribute("checked", "checked");
但是他网页上还有例外一段js代码
<script type="text/javascript" src="http://a.tbcdn.cn/sys/js/districtselector.js?t=20110206"></script>
<script type="text/javascript" src="http://a.tbcdn.cn/apps/tradeface/1.0/calculateServiceFee.js?t=20110520"></script>
<script type="text/javascript" src="http://a.tbcdn.cn/apps/tradeface/1.0/promotion_platform.js?t=20110520"></script>
<script type="text/javascript" src="http://a.tbcdn.cn/apps/tradeface/1.0/buynow_v1.2.js?t=20110520"></script>
<script>
        (function() {
        var promoData = null,
    
        orderData = {
            "relation" : {"cross_id":["b_7651003549"], "b_7651003549":["10130726347:10688817803"]},
            "orders" : {"b_7651003549":{"cross":false,"uid":"b_7651003549","buyerId":"715643095","sellerId":"82884615","divisionCode":"320902","postages":{"selected":"-1","list":{"1":{"title":"平邮","sum":"1000","value":"1"},"2":{"title":"快递","sum":"1500","value":"2"},"7":{"title":"EMS","sum":"2000","value":"7"}},"_cache":{"1":{"title":"平邮","sum":"1000","value":"1"},"2":{"title":"快递","sum":"1500","value":"2"},"7":{"title":"EMS","sum":"2000","value":"7"}},"fare":"1000"},"isBSeller":false,"exchange":false},"cross_id":{"cross":true,"uid":"cross_id"},"10130726347:10688817803":{"itemId":"10130726347","skuId":"10688817803","shopId":"61386385","sellerId":"82884615","price":"12000","amount":"1","codRate":"0","parent":"b_7651003549","uid":"10130726347:10688817803","pointRate":"0","isBSeller":false,"isBundleItem":false}}
        };
    
        TB.Promotion.init({
            disabled: false,
            apis:{
                amount:'json/asyncGetPromotion.htm?m=changeamount&from=buynow',
                bundle:'json/asyncGetPromotion.htm?m=changebundle&from=buynow',
                address:'json/asyncGetPromotion.htm?m=changeaddress&from=buynow'
            },
            template:{
                bundleList:'<select name="bundleList_{uid}">{options}</select>'
            },
            promoData:promoData,
            orderData:orderData
        });
 
    })();
    </script>
这样之后就出现错误了
“未将对象引用设置到对象的实例”
请高手帮帮忙啊,搞不定啊

解决方案 »

  1.   

    用Firefox的firebug插件调试下,看看哪个对象为空?
      

  2.   

    html 元素里面加“runat='server'"属性就可以获得了。
      

  3.   

    document.getElementById("<%=shipping2.ClientID%>")
      

  4.   


    document.getElementById("<%=服务器ID.ClientID%>")
      

  5.   


    谢谢8楼,原来是js的代码, 但是我进行winform编程,语言是C#,那我怎么使用这段代码?
      

  6.   

    document.getElementById(ID).value
    document.getElementById(ID).inertext
      

  7.   


    WinForm编程你怎么可能会有HTML代码???
    如果你想用C#语句获取页面上的控件的话,就给页面上的控件加上“runat='server'"属性注意,如果你的这些控件是放在数据绑定控件里的话,那么在读取它们时,要先读取包容它们的绑定控件开始,才能一层层地访问到它们,例外的,如果控件是直属于Page对象,也就是直接属于当前页面的,可以直接读取
      

  8.   

    这楼主NC,自己搞的什么都不清楚
    上面说网页情况,下面又说这是winform编程
    winform中还带js的
      

  9.   

    12#说我二? winform里面 就不能加载webbrowser控件,就不能用html 赋值,就不能用js,就不能操作网页我也无语了,还好问题解决了