<a class="comment-mod" onclick="alert('ss')" href="#">Comments</a>
If the user directly views the article list, all comments and comment boxes will not be displayed, but if the user directly locates this log through other pages such as the homepage's personal dynamics, then all comments should be displayed. The list page and the page that view a single entry are the same page, which requires me to determine whether the user is targeting the log. If so, the click event of the A tag is triggered through JS.
At first I tried some methods and took it for granted that the A tag has the onclick() event, but I found that it was not. Later, after searching for some information from the Internet, I successfully solved this problem^_^. The solution is to write different logic for IE and FF, with some of the code as follows:
<script>
var comment = ('a')[0];
if () {
// For IE
();
} else if () {
//FOR DOM2
var ev = ('HTMLEvents');
('click', false, true);
(ev);
}
</script>
grammar:
createEvent(eventType)
parameter
describe
eventType
The event module name of the Event object you want to obtain.
For a list of valid event types, see the Description section.
Return value
Returns the newly created Event object with the specified type.
Throw out
If the implementation supports the required event type, the method throws a DOMException exception with code NOT_SUPPORTED_ERR.
illustrate
This method will create a new event type specified by the parameter eventType. Note that the value of this parameter is not the name of the event interface to be created, but the name of the DOM module that defines that interface.
The following table lists the legal values of eventType and the event interfaces created for each value:
parameter
Event interface
Initialization method
HTMLEvents
HTMLEvent
iniEvent()
MouseEvents
MouseEvent
iniMouseEvent()
UIEvents
UIEvent
iniUIEvent()
After creating the Event object using this method, the object must be initialized using the initialization method shown in the above table. For more information about the initialization method, see the Event object reference.
This method is not actually defined by the Document interface, but by the DocumentEvent interface. If an implementation supports Event modules, the Document object implements the DocumentEvent interface and supports the method.
If the user directly views the article list, all comments and comment boxes will not be displayed, but if the user directly locates this log through other pages such as the homepage's personal dynamics, then all comments should be displayed. The list page and the page that view a single entry are the same page, which requires me to determine whether the user is targeting the log. If so, the click event of the A tag is triggered through JS.
At first I tried some methods and took it for granted that the A tag has the onclick() event, but I found that it was not. Later, after searching for some information from the Internet, I successfully solved this problem^_^. The solution is to write different logic for IE and FF, with some of the code as follows:
Copy the codeThe code is as follows:
<script>
var comment = ('a')[0];
if () {
// For IE
();
} else if () {
//FOR DOM2
var ev = ('HTMLEvents');
('click', false, true);
(ev);
}
</script>
grammar:
createEvent(eventType)
parameter
describe
eventType
The event module name of the Event object you want to obtain.
For a list of valid event types, see the Description section.
Return value
Returns the newly created Event object with the specified type.
Throw out
If the implementation supports the required event type, the method throws a DOMException exception with code NOT_SUPPORTED_ERR.
illustrate
This method will create a new event type specified by the parameter eventType. Note that the value of this parameter is not the name of the event interface to be created, but the name of the DOM module that defines that interface.
The following table lists the legal values of eventType and the event interfaces created for each value:
parameter
Event interface
Initialization method
HTMLEvents
HTMLEvent
iniEvent()
MouseEvents
MouseEvent
iniMouseEvent()
UIEvents
UIEvent
iniUIEvent()
After creating the Event object using this method, the object must be initialized using the initialization method shown in the above table. For more information about the initialization method, see the Event object reference.
This method is not actually defined by the Document interface, but by the DocumentEvent interface. If an implementation supports Event modules, the Document object implements the DocumentEvent interface and supports the method.