我是wordpress的新手。。。请帮助。。。无法使用此代码。。。[datatable}短代码是一个插件短代码(因此它确实存在)
Worpress页面:
<label>Client ID Nr</label> <input id="clientidnr" name="clientidnr" placeholder="9999" type="text"> <input type="button" style="background-color:#6D4053;color:white;" onclick="customidnr(0, \'shortc\')" name="submit" value="Submit" />
自定义JS:
function customidnr(idnr) {
var input;
if (idnr !== undefined && idnr !== 0) {
input = idnr;
storeDataidnr(input);
// alert("Storing idnr data1: " + input);
} else {
input = document.getElementById("clientidnr").value;
storeDataidnr(input);
// alert("Storing idnr data2: " + input);
}
jQuery.post(
ajaxurl,
{
\'action\': \'custom_id_nr\',
\'idnr\': input
},
function(response){
alert(\'The server responded: \' + response);
}
);
}
function storeDataidnr(clientidnr) {
alert("ML/TF Risk data will be displayed for ID Nr: " + clientidnr);
sessionStorage.setItem("idnr", clientidnr);
}
功能。PHP
/** jquery fix ********************************************************************************************** */
add_action( \'wp_enqueue_scripts\', \'load_old_jquery_fix\', 10 );
function load_old_jquery_fix() {
if ( ! is_admin() ) {
wp_deregister_script( \'jquery\' );
wp_register_script( \'jquery\', ( "//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" ), false, \'1.11.3\' );
wp_enqueue_script( \'jquery\' );
}
}
/** idnr **************************************************************************************************** */
add_action( \'wp_ajax_custom_id_nr\', \'custom_id_nr\' );
add_action( \'wp_ajax_nopriv_custom_id_nr\', \'custom_id_nr\' );
function custom_id_nr() {
$clidnr = intval( $_POST[\'idnr\'] );
$shortcode = sprintf(
\'[wpdatatable id=30 var1="%1$s"]\',
$clidnr
);
echo do_shortcode( $shortcode );
wp_die();
}