I create a link with text using html and i want to create when user click it goes to specific url. I new in javascript!!
here my code
<a class="dt-button add_new_table_entry DTTT_button DTTT_button_new" tabindex="0" aria-controls="table_1" href="#">
<span>Add new</span>
</a>
my script
$("dt-button add_new_table_entry DTTT_button DTTT_button_new").click(function () {
window.location="http://project.co/add-new/";
});
UPDATE I have create my script
let classic = document.getElementsByClassName('add_new DTTT_button DTTT_button_new');
for (var i=0; i < classic.length; i++) {
classic[i].addEventListener("click", clickfunc, false);
}
function.clickfunc(){
document.location.href="http://google.com";
}
but give error unexpected token ;
javascript打开新窗口
window.open(url, windowName, "height=200,width=200");
You do not have any class named add_new
. Using single unique class in getElementsByClassName
parameter is enough. Try the following:
let classic = document.getElementsByClassName('dt-button');
for (var i=0; i < classic.length; i++) {
classic[i].addEventListener("click", clickfunc, false);
}
function clickfunc(){
window.open("http://google.com","_blank");
}
use follwing code
$("dt-button add_new_table_entry DTTT_button
DTTT_button_new").click(function () {
window.open("http://project.co/add-new/");
});
create a function :
function openlink()
{
window.open("http://project.co/add-new/","mywindow","menubar=no,resizable=1,width=400,height=400");
}
then you call the function using this :
<a href="javascript:openlink();">Link Text</a>
Try it , it will work, here on click of class = add_new_table_entry, javascript click event gets called and in same window redirection happens we use window.location for redirection
Add new
$(".add_new_table_entry").click(function () {
window.location ="http://project.co/add-new/";
});
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.