Ik gebruik dit mooie kleine javascript om een veld te markeren terwijl de gebruiker eroverheen zweeft. Kun je me alsjeblieft vertellen of er een manier is om een onclick
-functie toe te voegen die als een link fungeert en naar een URL gaat?
<script>
$(function() {
$('tr').hover(function() {
$(this).css('background-color', '#eee');
$(this).contents('td').css({'border': '0px solid red', 'border-left': 'none', 'border-right': 'none'});
$(this).contents('td:first').css('border-left', '0px solid red');
$(this).contents('td:last').css('border-right', '0px solid red');
},
function() {
$(this).css('background-color', '#FFFFFF');
$(this).contents('td').css('border', 'none');
$('a#read_message.php').click(function(){ URL(); });
});
});
</script>
Antwoord 1, Autoriteit 100%
Probeer
window.location = url;
Gebruik ook
window.open(url);
Als u in een nieuw venster wilt openen.
Antwoord 2, Autoriteit 78%
Gebruik dit
gewoon
onclick="location.href='pageurl.html';"
Antwoord 3, Autoriteit 18%
In jQuery om een gebruiker naar een andere URL te sturen, kunt u het zo doen:
$("a#thing_to_click").on('click', function(){
window.location = "http://www.google.com/";
});
Op deze manier zal ook werken, maar het bovenstaande is de nieuwere correctere manier om deze tegenwoordig
te doen
$("a#thing_to_click").click(function(e){
e.preventDefault();
window.location = "http://www.google.com/";
});
Antwoord 4, Autoriteit 7%
function URL() {
location.href = 'http://your.url.here';
}
Antwoord 5, Autoriteit 6%
html
<input type="button" value="My Button"
onclick="location.href = 'https://myurl'" />
mvc
<input type="button" value="My Button"
onclick="location.href='@Url.Action("MyAction", "MyController", new { id = 1 })'" />
Antwoord 6, Autoriteit 5%
Als u een link op een nieuw tabblad wilt openen, kunt u:
$("a#thing_to_click").on('click',function(){
window.open('https://yoururl.com', '_blank');
});
Antwoord 7, Autoriteit 3%
Als u te maken hebt met <a>
TAG, en u wilt onderbreken naar de standaard href
U moet this
in plaats daarvan.
Ga naar de standaard-URL (Yahoo):
<a href="https://yahoo.com" onclick="location.href='https://google.com';">
Ga naar nieuwe URL (Google) onclick
:
<a href="https://yahoo.com" onclick="this.href='https://google.com';">
Door this
te gebruiken onderbreek je de huidige browser onclick
-gebeurtenis en verander je href
voordat je doorgaat met het standaardgedrag van <a href='...
Antwoord 8
Ik weet niet helemaal zeker of ik de vraag begrijp, maar bedoel je zoiets?
$('#something').click(function() {
document.location = 'http://somewhere.com/';
} );
Antwoord 9
probeer
location = url;