Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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
在不在jquery中工作的情况下(“单击”)_Jquery - Fatal编程技术网

在不在jquery中工作的情况下(“单击”)

在不在jquery中工作的情况下(“单击”),jquery,Jquery,你好,朋友,在我的代码中,我使用了on()函数来处理在负重后创建的表格行。我只想通过单击.delRow删除这些行,但我的代码不起作用。我不知道确切的问题是什么。请检查下面的我的cod,或者您可以检查 使用的Jquery版本 <script src="http://code.jquery.com/jquery-1.10.2.js" language="javascript"></script> HTML <table width="100%" cellspaci

你好,朋友,在我的代码中,我使用了
on()
函数来处理在负重后创建的表格行。我只想通过单击
.delRow
删除这些行,但我的代码不起作用。我不知道确切的问题是什么。请检查下面的我的cod,或者您可以检查

使用的Jquery版本

<script src="http://code.jquery.com/jquery-1.10.2.js" language="javascript"></script>

HTML

<table width="100%" cellspacing="0" cellpadding="0" border="0" id="emailTable">
    <tbody>
        <tr>
            <td align="center" colspan="2" >
                <strong>Share this greeting with your friend</strong>
            </td>
        </tr>
        <tr>
            <td width="417" align="right">
                <input type="text" placeholder="Enter Friend's Email ID" class="mail" id="SendMail" name="SendMail">
            </td>
            <td width="156">  <div class="addRow">Add more Recipients</div></td>
        </tr>
    </tbody>
</table>

与您的朋友分享此问候
添加更多收件人
脚本

$(document).ready(function(e) {     
    $('.delRow').on( "click", function( event ) {
        $(this).parent('tr').remove();
    /*alert('hi');*/
    });
    $('.addRow').click(function(){
        $('#emailTable').append("<tr><td  align='right'><input type='text' placeholder=\"Enter Friend's Email ID\" class='mail' id='SendMail' name='SendMail'></td><td class='delRow'> <img src='images/Cross.png' alt=' ' ></td></tr>")
    })
});
$(文档).ready(函数(e){
$('.delRow')。在(“单击”上,函数(事件){
$(this.parent('tr').remove();
/*警报(“hi”)*/
});
$('.addRow')。单击(函数(){
$('#emailTable')。附加(“”)
})
});

请帮助我,伙计们

将单击事件委托给元素的
静态父项
文档

试试看


将单击事件委托给元素的
静态父级
文档

试试看

您需要在动态创建delRow元素时使用

$('#emailTable').on("click", '.delRow',function (event) {
    $(this).parent('tr').remove();
    /*alert('hi');*/
});
演示:

您需要使用,因为delRow元素是动态创建的

$('#emailTable').on("click", '.delRow',function (event) {
    $(this).parent('tr').remove();
    /*alert('hi');*/
});
演示: