We often see this effect: click a button to copy the content in a region to the clipboard. In fact, this function is not difficult to implement. The core is to use the clipboardData method of the window sub-object: setData ()
Syntax:
ClipboardData. setData (sDataFormat, sData)
Parameters:SDataFormat: Format of the content to be copied; sData: content to be copied.
Return Value:True is returned for successful replication; false is returned for failed replication.
Copy codeThe Code is as follows:
<Script language = "JavaScript">
Function jianqie (id)
{Var id;
Var text = document. all (id). innerText
If (clipboardData. setData ("text", text ))
{Alert ("Copied successfully! ")}
Else
{Alert ("copying failed! ")}
}
</Script>
In js, the match function uses the regular expression mode to perform a search for a string and returns the result containing the search as an array. Usage:
StringObj. match (rgExp)
StringObj is required. String object or String text to search.
RgExp is required. It is a regular expression object that contains the regular expression mode and available flag. It can also be a variable name or string text that contains the regular expression mode and available signs.
If no match is found in the match Function Method in js, null is returned. If a match is found, an array is returned and the attributes of the global RegExp object are updated to reflect the matching result. The array returned by the match function in JavaScript has three attributes: input, index, and lastIndex. The Input attribute contains the entire searched string. The Index attribute contains the position of the matched substring in the entire searched string. The LastIndex attribute contains the next position of the last character in the last match. If the global sign (g) is not set, the 0 element of the array contains the entire match, and the 1st to n element contains any child match that has occurred during the match. This is equivalent to the exec method without a global flag. If a global flag is set, elements 0 to n contain all matches.
The following example demonstrates the usage of the match function in js:
Copy codeThe Code is as follows:
Function MatchDemo (){
Var r, re; // declare the variable.
Var s = "The rain in Spain falls mainly in the plain ";
Re =/ain/I; // create the regular expression mode.
R = s. match (re); // try to match the search string.
Return (r); // return the place where "ain" appears for the first time.
}
This example describes how to use the match function in js with g flag settings.
Copy codeThe Code is as follows:
Function MatchDemo (){
Var r, re; // declare the variable.
Var s = "The rain in Spain falls mainly in the plain ";
Re =/ain/ig; // create the regular expression mode.
R = s. match (re); // try to match the search string.
Return (r); // The returned array contains all "ain"
The following lines of code demonstrate the usage of the match function in the string text js.
Copy codeThe Code is as follows:
Var r, re = "Spain ";
R = "The rain in Spain". replace (re, "Canada ");
The match () method is used to find the specified value from a string. This method is similar to indexOf () and lastindexOf (). The difference is that it returns the specified value, instead of specifying the position in the string. The indexOf () and lastindexOf () Methods return the position number. If no value is found,-1 is returned. Case Sensitive
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Var str = "Hello world! "
Document. write (str. match ("world") + "")
Document. write (str. match ("World") + "")
Document. write (str. match ("worlld") + "")
Document. write (str. match ("world! "))
</Script>