drxpt06820 2015-10-08 02:09
浏览 40
已采纳

单击复选框时停止触发功能

I am using jquery to print the following table. Table has two columns. one for the values and other for the check boxes. Problem I am facing is when I click a checkbox, it is triggering the function which is supposed to be triggered only when the value clicked.

Can somebody tell me how to stop triggering the function when a check box is clicked?

PHP code that prints the table

<table border='1' cellspacing='12' cellpadding='4' style='border-collapse: collapse' width='700' id=topictable >

<?php while ($row = mysql_fetch_assoc($results)) {
    $topic = $row['topic']; 
?>
<tr bgcolor='white'>
<td class='value'><a href='#'><?php $topic ?></a></td>
<td bgcolor='white'width='5%'><input type=checkbox name=chekboxTopic[] value= <?php $topic ?> </td>
</tr>
<?php
}
?>
</table>

Java script

$(document).on("click","#topictable td", function() {
    // to set the session variable`enter code here`
    var strSelectedTopic = ($( this ).text());
    alert(strSelectedTopic);
    var switchval = "setsessiontopic";
     var param = "switchval=" + switchval + "&topic=" + strSelectedTopic;
     ajaxSend(param);
    var form = document.getElementById("abcd");
    form.action = "design.php"
    form.target = "_blank";
    form.submit();
    return false;

});
  • 写回答

1条回答 默认 最新

  • dreamwind1985 2015-10-08 04:21
    关注

    Couple things.

    1. Close off your inputs
    2. Change what is supposed to be clicked; make it more specific

    Demo: http://jsfiddle.net/dL3s3acn/

    <table border='1' cellspacing='12' cellpadding='4' style='border-collapse: collapse' width='700' id=topictable >
    <?php
        while ($row = mysql_fetch_assoc($results)) {
            $topic = $row['topic'];
    ?>
        <tr bgcolor='white'>
            <td class="value"><a href="#"><?php $topic ?></a></td>
            <td bgcolor="white" width="5%"><input type="checkbox" name="chekboxTopic[]" value="<?php $topic ?>" /></td>
        </tr>
    <?php
        }
    ?>
    </table>
    <script>
    // Click on the class ".value" not "td", that is too broad
    $(document).on("click","#topictable .value", function() {
        // to set the session variable`enter code here`
        var strSelectedTopic = ($(this).text());
        alert(strSelectedTopic);
        var switchval   =   "setsessiontopic";
        var param       =   "switchval="+switchval+"&topic="+strSelectedTopic;
        ajaxSend(param);
        var form        =   document.getElementById("abcd");
        form.action     =   "design.php"
        form.target     =   "_blank";
        form.submit();
        return false;
    });
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算