C# 方法'没有重载;setAttribute';采取';2';论据

C# 方法'没有重载;setAttribute';采取';2';论据,c#,visual-studio-2005,mshtml,setattribute,C#,Visual Studio 2005,Mshtml,Setattribute,我无法为元素设置新属性,VS 2005返回以下代码错误: 错误1方法“setAttribute”没有重载接受“2”个参数 错误2方法“setAttribute”没有重载接受“2”个参数 错误3方法“setAttribute”没有重载接受“2”个参数 有什么问题吗 谢谢大家! try { IHTMLElementCollection AllElements = document.all; foreach (IHTMLElement Element in AllElements)

我无法为元素设置新属性,VS 2005返回以下代码错误:

错误1方法“setAttribute”没有重载接受“2”个参数 错误2方法“setAttribute”没有重载接受“2”个参数 错误3方法“setAttribute”没有重载接受“2”个参数

有什么问题吗

谢谢大家!

try
{
   IHTMLElementCollection AllElements = document.all;
   foreach (IHTMLElement Element in AllElements)
   {                   
      if (Element.tagName.ToUpper() == "IMG")
      {   
         if (Element.offsetHeight <= 40 && Element.offsetHeight >= 20)
         {
            if (Element.offsetWidth <= 160 && Element.offsetWidth >= 130)
            {
               Element.setAttribute("width", Element.offsetWidth);
               Element.setAttribute("height", Element.offsetHeight);
               Element.setAttribute("src", "images/newimage.png");
            }
         }
      }
   }            
}   
catch (Exception e)
{
   string erro = e.Message;
   System.Windows.Forms.MessageBox.Show(erro);
}
试试看
{
IHTMLElementCollection等位基因=document.all;
foreach(等位基因中的IHTMlement元素)
{                   
if(Element.tagName.ToUpper()=“IMG”)
{   
如果(Element.offsetHeight=20)
{
if(Element.offsetWidth=130)
{
Element.setAttribute(“宽度”,Element.offsetWidth);
Element.setAttribute(“高度”,Element.offsetHeight);
setAttribute(“src”、“images/newimage.png”);
}
}
}
}            
}   
捕获(例外e)
{
字符串erro=e.消息;
System.Windows.Forms.MessageBox.Show(erro);
}
From:看来第三个参数应该是可选的

lFlags[输入,可选] 类型:长

LONG,指定是否使用区分大小写的搜索来定位属性。可以是以下值之一:

一,

strAttributeName案受到尊重

0

无论大小写,都要匹配StratTributerName

您可以尝试传入0或1

Element.setAttribute("width", Element.offsetWidth, 0);
Element.setAttribute("height", Element.offsetHeight, 0);
Element.setAttribute("src", "images/newimage.png", 0);
添加上述Hans评论中的信息(如下所示):


“VS2005非常陈旧。C#v2还不支持可选参数。”-Hans Passant:)

。setAttribute接受3个参数。第3个参数是可选的。。。我在代码中找不到问题。然而,如果您测试的浏览器是IE9,那么IE9中就有一个已知的bug。否则,我唯一的想法可能是元素在javascript中是一个保留字,可能会导致一些问题。C#v2还不支持可选的论点。我认为否决票和接近票是不合理的。如果你查一下,你会发现第三个参数是可选的。我认为没有理由期望任何人知道这是因为(间接地)旧的编译器版本。根据Hans Passants的评论,您应该指定VS 2005显然不支持可选参数(旧的编译器版本)。这才是真正的问题。