HtmlElementCollection.GetElementsByName(String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a collection of elements by their name.
public:
System::Windows::Forms::HtmlElementCollection ^ GetElementsByName(System::String ^ name);
public System.Windows.Forms.HtmlElementCollection GetElementsByName (string name);
member this.GetElementsByName : string -> System.Windows.Forms.HtmlElementCollection
Public Function GetElementsByName (name As String) As HtmlElementCollection
Parameters
- name
- String
The name or ID of the element.
Returns
An HtmlElementCollection containing the elements whose Name property match name
.
Examples
The following code example finds a FORM
object using its name, and submits its data to the server programmatically. The code example requires that your application hosts a WebBrowser control named webBrowser1
.
private void SubmitForm(String formName)
{
HtmlElementCollection elems = null;
HtmlElement elem = null;
if (webBrowser1.Document != null)
{
HtmlDocument doc = webBrowser1.Document;
elems = doc.All.GetElementsByName(formName);
if (elems != null && elems.Count > 0)
{
elem = elems[0];
if (elem.TagName.Equals("FORM"))
{
elem.InvokeMember("Submit");
}
}
}
}
Private Sub SubmitForm(ByVal FormName As String)
Dim Elems As HtmlElementCollection
Dim Elem As HtmlElement
If (WebBrowser1.Document IsNot Nothing) Then
With WebBrowser1.Document
Elems = .All.GetElementsByName(FormName)
If (Not Elems Is Nothing And Elems.Count > 0) Then
Elem = Elems(0)
If (Elem.TagName.Equals("FORM")) Then
Elem.InvokeMember("Submit")
End If
End If
End With
End If
End Sub
Remarks
While the Id property of an HtmlElement must be unique, multiple elements can use the same Name property.
Applies to
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈