简体   繁体   中英

Change href attribute in jquery with php

$('.buttonFinish').addClass('btn btn-default');

Jquery code for the submit looks like this:

finish  : $('<a>'+options.labelFinish+'</a>').attr("href","#").addClass("buttonFinish")

I need to replace "#" in href with a variable that I can send thru my PHP code.

I tried to do this:

 finish  : $('<a>'+options.labelFinish+'</a>').attr("href","<?php echo $someVariable;?>").addClass("buttonFinish")

where $someVariable is defined in the PHP code where the form submission link will point to

You can define a variable in php and call it in JS. For example...

PHP

$someVariable = <?php echo $something ?>

JS

finish  : $('<a>'+options.labelFinish+'</a>').attr("href", $someVariable).addClass("buttonFinish")
var someVariable = "<?php echo $something ?>";

finish  : $('<a>'+options.labelFinish+'</a>').attr("href", someVariable).addClass("buttonFinish")

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