是否有任何可能的格式添加写这个......
PHP:
wp_localize_script( 'script', 'script_object_' . $ID, array( 'name' => whatever ) );
....
echo '<form onsubmit=\'myfunction("'. $ID .'"); return false\'>'
JS:
function myfunction( ID ){
alert( script_object_ + ID +.name );
}
用js ???写的一些方法
答案 0 :(得分:0)
wp_localize_script( 'script', 'script_object_' . $ID, array( 'name' => whatever ) );
....
echo "<form onsubmit='myfunction(\"script_object_".$ID."\", ".json_encode(array( 'name' => whatever ))."); return false'>";
function myfunction( elname, json ){
alert( elname );
console.log(json)
var json2 = JSON.parse(json);
console.log(json2);
}
或者如果您愿意: