Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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
Javascript 如何禁用单击事件 函数插入问题(表单){ var x=“(单击加号查找前面的问题)”; 如果(qnum==){ $('mainPlusbutton')。替换为(x); } //将行追加到表代码中,此问题不需要 }.... $('.plusimage').live('click',函数(){ plusbutton($(此)); }); 功能加号按钮(加号){ //设置全局信息 plusbutton_clicked=plus_id; //使用iframe显示外部页面 var src=“previousquestions.php”; $.modal(“”); 返回false; } $('.plusimage').live('click',function()){ 如果(qnum!=){ plusbutton($(此)); } });_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何禁用单击事件 函数插入问题(表单){ var x=“(单击加号查找前面的问题)”; 如果(qnum==){ $('mainPlusbutton')。替换为(x); } //将行追加到表代码中,此问题不需要 }.... $('.plusimage').live('click',函数(){ plusbutton($(此)); }); 功能加号按钮(加号){ //设置全局信息 plusbutton_clicked=plus_id; //使用iframe显示外部页面 var src=“previousquestions.php”; $.modal(“”); 返回false; } $('.plusimage').live('click',function()){ 如果(qnum!=){ plusbutton($(此)); } });

Javascript 如何禁用单击事件 函数插入问题(表单){ var x=“(单击加号查找前面的问题)”; 如果(qnum==){ $('mainPlusbutton')。替换为(x); } //将行追加到表代码中,此问题不需要 }.... $('.plusimage').live('click',函数(){ plusbutton($(此)); }); 功能加号按钮(加号){ //设置全局信息 plusbutton_clicked=plus_id; //使用iframe显示外部页面 var src=“previousquestions.php”; $.modal(“”); 返回false; } $('.plusimage').live('click',function()){ 如果(qnum!=){ plusbutton($(此)); } });,javascript,jquery,html,Javascript,Jquery,Html,您应该使用$('.plusimage')。关闭('click')禁用单击事件(jQuery

您应该使用
$('.plusimage')。关闭('click')
禁用单击事件(jQuery<1.7不推荐使用unbind和live,但仍然支持)

如果您正在寻找只允许在图元上单击一次的方法,则可以使用以下方法:

$('.plusimage').live('click', function() {
  if (qnum != <?php echo (int)$_SESSION['textQuestion']; ?>) {
    plusbutton($(this));
  }
});

也许这并不完全正确,因为它并没有在JSFIDLE中运行,但如果您加入Tom的问题,它应该会给您一些提示

可能原因是我删除了一些php,因为没有办法回送或检查会话变量,尽管我认为您应该首先检查$\u会话变量是否存在

@AddTom:对PHP echo做了一些小修改

//Click event activated only if the disabled class is not set
$('form table a:not(.disabled)').on('click', function() {
   plusbutton($(this));
});
函数insertQuestion(form){
var x=“(单击加号查找前面的问题)”;

我只希望当满足if语句
if(qnum==){
时禁用onclick,onclick事件始终处于启用状态,直到满足此if语句。您的代码能够做到这一点吗?解除live()的绑定是die(),但现在它是开()和关()。要使某个事件只在其一个()之后发生我的意思是,我应该在if语句中添加什么,这样当满足if语句时,它将禁用onclick事件,在这段代码似乎随时都会禁用onclick事件的时候,我只想在if语句已经满足时禁用它。所以在if语句中,我应该做您所说的事情还是应该做类似的事情
$('.plusimage')。解除绑定('click'))
在if语句中?在if语句中…但请检查我的编辑,用另一种方法实现这一点。我想要的是,如果满足if语句,它将禁用onclick直通方式。如果查看if语句内部,它将立即替换图像,我想在满足if语句时立即禁用on click事件。So哪一行代码最适合这样做并包含在if语句中?然后在
$('.plusimage')之后插入
$('.plusimage')。关闭('click');
$(''mainplusbbutton')。替换为(x);
,这样您将停用click事件。好的,我会尝试一下,希望它能起作用。我会让您知道结果……我尝试了
$('.plusimage')).off('click');
但它没有禁用click事件
$('.plusimage').live('click', function() {
  if (qnum != <?php echo (int)$_SESSION['textQuestion']; ?>) {
    plusbutton($(this));
  }
});
function insertQuestion(form) {   

    var x = "<img src='Images/plussigndisabled.jpg' width='30' height='30' alt='Look Up Previous Question' class='plusimage' name='plusbuttonrow'/><span id='plussignmsg'>(Click Plus Sign to look <br/> up Previous Questions)</span>" ;

    if (qnum == <?php echo (int)$_SESSION['textQuestion']; ?>) {
       $('#mainPlusbutton').replaceWith(x);
       //If the condition hold, then deactivate the click event!
       $('form table a').addClass('disabled');
    }
    else{
       //If the condition is false, click event is activated removing the disabled class
       $('.form table a').removeClass('disabled');
    }
    //append rows into a table code, not needed for this question
}
//Click event activated only if the disabled class is not set
$('form table a:not(.disabled)').on('click', function() {
   plusbutton($(this));
});
function insertQuestion(form) {   

    var x = "<img src='Images/plussigndisabled.jpg' width='30' height='30' alt='Look Up Previous Question' class='plusimage' name='plusbuttonrow'/><span id='plussignmsg'>(Click Plus Sign to look <br/> up Previous Questions)</span>" ;

 <?
 //to avoid typecasting just declare the variable as a number
 $text_question_res=0;

session_start(); //If session has not started previously
if(isset($_SESSION['textQuestion']) ) $text_question_res.=$_SESSION['textQuestion'];
echo <<<EOD

if (qnum == $text_question_res) //expected to be a number

EOD;

//    if (qnum == <?php echo (int)$_SESSION['textQuestion']; ?>) {


       $('#mainPlusbutton').replaceWith(x);
       //If the condition hold, then deactivate the click event!
       $('.plusimage').addClass('disabled');
    }
    else{
       //If the condition is false, click event is activated removing the disabled class
       $('.plusimage').removeClass('disabled');
    }
    //append rows into a table code, not needed for this question
}