<A class = "comment-mod" onclick = "alert ('ss')" href = "#"> comment </a>
If you directly view the document list, all comments and comments are not displayed. However, if you dynamically locate this log on other pages, such as the homepage, then all comments should be displayed. The list page is the same as the page for viewing a single entry, which requires me to determine whether the user has located the log. If yes, trigger the Click Event of the tag through JS.
At first, I tried some methods and thought that the tag and the button had an onclick () event. I found no. After searching some information on the Internet, successfully solved this problem ^_^. The solution is to write different logic for IE and FF. Some code is as follows:
Copy codeThe Code is as follows:
<Script>
Var comment = document. getElementsByTagName ('A') [0];
If (document. all ){
// For IE
Comment. click ();
} Else if (document. createEvent ){
// FOR DOM2
Var ev = document. createEvent ('htmlevents ');
Ev. initEvent ('click', false, true );
Comment. dispatchEvent (ev );
}
</Script>
Syntax:
CreateEvent (eventType)
Parameters
Description
EventType
The name of the Event module of the Event object to be obtained.
For a list of valid event types, see the description section.
Return Value
Returns the newly created Event object with the specified type.
Throw
If the implementation supports the required event type, this method throws the DOMException code NOT_SUPPORTED_ERR.
Description
This method creates a new event type, which is specified by the eventType parameter. Note: The value of this parameter is not the name of the event interface to be created, but the name of the DOM module of that interface.
The following table lists the valid values of eventType and the event interfaces created for each value:
Parameters
Event Interface
Initialization Method
HTMLEvents
HTMLEvent
IniEvent ()
MouseEvents
MouseEvent
IniMouseEvent ()
UIEvents
UIEvent
IniUIEvent ()
After you create an Event object using this method, you must use the initialization method shown in the table to initialize the object. For more information about the initialization method, see the Event object reference.
This method is not defined by the Document interface, but by the deletevent interface. If an implementation supports the Event module, the Document Object implements the deleentevent interface and supports this method.