通过javascript设置隐藏变量在Wordpress 3.3.1管理插件页面中不起作用

setting hidden vars by javascript not working in Wordpress 3.3.1 admin plugin pages

本文关键字:插件 管理 不起作用 通过 隐藏 设置 变量 Wordpress javascript      更新时间:2023-09-26

我需要从自定义管理插件页面中设置隐藏变量(因为在wordpress中不允许使用url查询参数进行回发(权限)。例如

<script>
function change_event(invar1)
{
    document.getElementById('my_tag').onclick = function(){new_func();}
//alert (invar1);  //happiness
//Set hidden vars   //oh crap, script breaks , next alert does not alert, and hdnCmd remains blank after this
document.getElementById('hdnCmd').value=invar1; 
    alert ("hdn = " + document.getElementById('hdnCmd').value); 
     //reload the window
     //window.location.reload();
}
</script>

Thx

已解决。

Pointy thx,尝试了登记簿,但没有成功。因此,找到了一个插件,允许WP管理页面在url中使用params。

然后在另一页中,。。。这很有趣。。。并且也不必注册脚本。我不得不使用下拉菜单来选择"菜单项",例如三明治、皮塔面包和沙拉,为这些菜单项分配馅料,。。我现在不得不使用javascrit和hiddeen输入。结果是双管齐下。。也使用Jquery

在php方面,我的表中的每一行都是用数据库数据构建的(edit、del、ins、updt)我从url参数中设置了隐藏的var。。

$Sel = $_GET["sel"]

例如。

   foreach ($myrows as $row) 
   {        
if($row->F_Id == $_GET["recId"] and $_GET["Action"] == "Edit")  
{
$Sel = $_GET["sel"]
?>
    <input  name="Select2" id="Select2" value="<?php echo $Sel;?>" >
    <input  type="hidden" name="hdnSelect2" id="hdnSelect2" value="<?php echo $Sel;?>" > 

以及下拉列表(有点不同,因为我使用了一个关联数组,这样我就可以获得数据行的PK和显示的描述

<script> 
//use jQuery in place of hash if in WP
jQuery(document).ready(function(){ 
jQuery("#MenuItems option[value='jQuery('#hdnSelect2').val()']").attr('selected', 'selected'); 
jQuery("#MenuItems").prop("selectedindex",jQuery('#hdnSelect2').val());
var x = jQuery('#hdnSelect2').val();
jQuery("#MenuItems").val(x); 
});
</script>
<script type="text/javascript">      //From/for the Selects onchange event
function SetDDLValueOnChange (objDropDown) {
var objHidden = document.getElementById("hdnSelect");
//clean up objDropDown (ie 'this') from the dropdown's onchange event
if ( objDropDown.value.length > '1')
{   
    objHidden.value = objDropDown.value.substr(0,1);
    //alert (objDropDown.value);  //results in eg 2[2]
    objDropDown.value = objHidden.val;
}
}