简体   繁体   中英

how do I add a second variable to a simple javascript function?

This is part of a simple script that will produce a warning popup. Currently, it works for any links with a ":" as seen below. I'd like to add a second variable, so it will work for EITHER a ":" OR "#tabs-2".

$(function(){
$('a[href*=":"]').click(ask) // all links that have a colon in them.
})

Thanks!

First of all, you're not seeking to add a 'variable'; there's no variables at play here. What you're seeking to do is to widen your jQuery selector (a string) to match more elements than it currently does.

This is achieved by specifying the variants separated by commas:

$('a[href*=":"], #tabs-2') //<-- note comma

Beware, though: #tabs-2 sounds, to me, like a container, so you might actually mean something like

$('a[href*=":"], #tabs-2 a')

Just use a comma and specify another selector:

$(function(){
$('a[href*=":"], #tabs-2').click(ask) // all links that have a colon in them.
})

用作:

$('a[href*=":"], #tabs-2').click(ask);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM