<script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
//waits till the document is ready
$(document).ready(function() {
//onclick function
$('button.butter').click(function(){
//code will only run on certain url
if (pathname.indexOf("google")>= 0){
alert('This doesn't work anymore!');
//replacer
$("a[href*='https://google.com']").attr('href',('http://www.google.com/search?q' + $('#FormID').val()));
}
else{
alert('Wrong page');
}
});
});
</script>
It doesn't alert, but why? This was working earlier and I forgot to save it. It should replace the url with another one plus the value from a field. edit: head, html, etc. tags are there.
<button class="butter">Press</button>
You don't declare pathname
anywhere, this:
if (pathname.indexOf("google")>= 0){
should result in an error in your console.
我想你想要的是location.pathname
而不是pathname
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.