Neither is good.
Behaviour should be configured independent of the actual markup. For instance, in jQuery you might do something like
$('#the-element').click(function () { /* perform action here */ });
in a separate <script>
block.
The advantage of this is that it
- Separates markup and behaviour in the same way that CSS separates markup and style
- Centralises configuration (this is somewhat a corollary of 1).
- Is trivially extensible to include more than one argument using jQuery’s powerful selector syntax
Furthermore, it degrades gracefully (but so would using the onclick
event) since you can provide the link tags with a href
in case the user doesn’t have JavaScript enabled.
Of course, these arguments still count if you’re not using jQuery or another JavaScript library (but why do that?).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…