0

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

<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>

谢谢

4

1 回答 1

0

解决。

Pointy thx,尝试了注册脚本,但没有成功。因此,找到了一个允许 WP 管理页面在 url 中使用参数的插件。

然后在另一个页面中,...这很有趣...并且也不必注册脚本。我必须使用下拉菜单来选择“MenuItem”,例如三明治、皮塔面包和沙拉来为这些菜单项分配填充物,..我现在必须使用 javascrit 和隐藏输入。原来是2管齐下的方法..也使用Jquery

在 php 方面,我用其中的 db 数据构造的表的每一行(编辑、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;?>" > 

和下拉列表(有点不同,因为我使用了关联数组,这样我就可以获得 Datarow 的 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;
}
}  
于 2012-02-16T09:53:30.017 回答