2
    <form id="QandA" action="<?php echo htmlentities($action); ?>" method="post">

    <table id="question">

    <tr>
    <td colspan="2">
    <a onclick="return plusbutton();">
    <img src="Images/plussign.jpg" width="30" height="30" alt="Look Up Previous Question" class="plusimage" id="mainPlusbutton" name="plusbuttonrow"/>
    </a>
    <span id="plussignmsg">(Click Plus Sign to look up Previous Questions)</span>
    </td>
    </tr>
    </table>


    </form>

在上面的代码中,当满足 if 语句时,我可以用另一个图像替换一个图像。但我的问题是,当图像被替换时,它不会禁用点击事件。我的问题是,当图像被替换时,如何禁用 onclick 事件onclick="return plusbutton();

4

3 回答 3

4

您从plusbutton函数本身中禁用。首先,将元素传递给函数,如下所示:

<a onclick="return plusbutton(this);">

然后在函数中禁用它:

function plusbutton(element) {
    element.onclick = '';
    /* then do whatever plusbutton did before */
}

但是由于您使用的是 jQuery,因此最好使用处理程序。所以给链接一个id而不是onclick,像这样:

<a id="plusbutton" href="#">

并使用jQuery.one()绑定只发生一次的点击处理程序:

$(document).ready(function() {
    $('#plusbutton').one('click', function(ev) {
        plusbutton();
        return false;
    });
});
于 2012-11-25T13:07:05.077 回答
1
event.preventDefault(); 

将阻止元素继续其正常功能。

于 2012-11-25T13:07:57.523 回答
0

试试这个代码:

$('#addQuestionBtn').bind("click",function(){
    $('#addQuestionBtn').unbind("click");   
    insertQuestion(document.form);
});

还有你的html:

<input id="addQuestionBtn" name="addQuestion" type="button" value="Add Question" />
于 2012-11-25T13:07:34.867 回答