Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用带有函数变量的javascript启用/禁用onclick事件_Php_Javascript - Fatal编程技术网

Php 使用带有函数变量的javascript启用/禁用onclick事件

Php 使用带有函数变量的javascript启用/禁用onclick事件,php,javascript,Php,Javascript,这是我在论坛上的第一个问题,希望能得到一些有用的快速回复 以下是我的php代码: <a href="<?php echo $sp['url']; ?>" id="bstd<?php echo $sp['Id']; ?>" target="_blank" onclick="clk('<?php echo $sp['Id']; ?>','<?php echo $_REQUEST['uid']; ?>')"><img src="imag

这是我在论坛上的第一个问题,希望能得到一些有用的快速回复

以下是我的php代码:

<a href="<?php echo $sp['url']; ?>" id="bstd<?php echo $sp['Id']; ?>" target="_blank" onclick="clk('<?php echo $sp['Id']; ?>','<?php echo $_REQUEST['uid']; ?>')"><img src="images/add.jpj"></a>

以及以下javascript函数:

<script>
function clk(a,b){
......... the ajax code to use a,b as variables 
........
}
</script>

功能时钟(a、b){
使用a、b作为变量的ajax代码
........
}
这一切都很好。。。 但是 在另一个javascript函数中。。。我想启用/禁用的和href的onclick

<script>
function disb(p){
if(p>5){
        av=document.getElementById(bstd); //working fine
        av.setAttribute("href", "#");  //working fine
        av.style.cursor="default";  //working fine
        av.onclick = cancel;  //not working... i want to disable the onclick.
    }else{
        av=document.getElementById(bstd);  //working fine
        av.setAttribute("href", ???);  //i want the previous code url link automatically..as it was dynamic and coming from php.
        av.style.cursor="pointer";  //working fine
        av.onclick = ???;  //i want the onclick function clk(with the dynamic php values).

    }
}
</script>

职能解散(p){
如果(p>5){
av=document.getElementById(bstd);//工作正常
av.setAttribute(“href”,“#”);//工作正常
av.style.cursor=“default”//工作正常
av.onclick=cancel;//不工作……我想禁用onclick。
}否则{
av=document.getElementById(bstd);//工作正常
av.setAttribute(“href”,???);//我想自动获取前面的代码url链接..因为它是动态的,来自php。
av.style.cursor=“pointer”//工作正常
av.onclick=???;//我想要onclick函数clk(带有动态php值)。
}
}
我知道这不容易理解。。我想要的。。。所以这里有一个简短的描述

我有一个图像“a1”点击这个我数多少次我点击这个图像。。。现在在这之后。。。如果我点击超过5次。。。那么只有。。。应该启用标记的onclick。。。 否则,每次单击都应该禁用onclick of标记(我有另一个向下计数的图像,所以无论是启用还是禁用,每次都需要禁用它)


我不知道这有没有意义。。。但我需要解决方案…

将您的
Id
uid
移动到data-*属性,然后您可以定义
onclick
,并且可以在不丢失它们的情况下进行更改。还保留href的备份

<a href="<?php echo $sp['url']; ?>"
   data-href="<?php echo $sp['url']; ?>"
   id="bstd<?php echo $sp['Id']; ?>"
   target="_blank"
   data-Id="<?php echo $sp['Id']; ?>"
   data-uid="<?php echo $sp['uid']; ?>"
   onclick="clk(this.getAttribute('data-Id'), this.getAttribute('data-uid'))"
><img src="images/add.jpj"></a>

首先,我衷心感谢你的回复。。。我试过了。。。它是有效的…首先我衷心感谢你的回复。。。它对我有用。。。。非常感谢。。。我为此苦苦挣扎,浪费了三天。。。我学到了一个新东西。。。非常感谢你。
function disb(p) {
    var av = document.getElementById(bstd); // remember to use var
    if (p > 5) {
        av.href = "#"; // remove href
        av.style.cursor = "default";
        av.onclick = function () { // prevent action
            return false;
        };
    } else {
        av.href = av.getAttribute('data-href'); // restore href
        av.style.cursor = "pointer";
        av.onclick = function () { // default action
            return clk(
                this.getAttribute('data-Id'),
                this.getAttribute('data-uid')
            );
        };
    }
}