跨浏览器jQuery - Firefox问题

时间:2013-01-14 16:28:57

标签: javascript jquery google-chrome firefox dynamic

这段代码:

jQuery(function($){
        var $button = $('#addrowbutton'),
            $row = $('.addrow').clone();
        $button.click(function(){
            $row.clone().insertBefore( $button );
        });
    });

无法在Firefox上运行,但在Chrome& IE。

这是通话按钮:

<input type="button" class=button id="addrowbutton" name="addrowbutton" value="Add Row" style="height: 2em;"/>

任何想法的家伙?提前谢谢。

1 个答案:

答案 0 :(得分:1)

我已将您的代码放在jsfiddle中并在Firefox中进行测试。对我来说很好。

http://jsfiddle.net/nadjib/X48xB/

HTML:

<div class="addrow">Row</div>
<input type="button" class=button id="addrowbutton" name="addrowbutton" value="Add Row" style="height: 2em;" />

jQuery的:

var $button = $('#addrowbutton'),
    $row = $('.addrow').clone();

$button.click(function () {
    $row.clone().insertBefore(this);
});

我正在使用“this”而不是$按钮,因为“this”就是您点击的内容(即此处的按钮)。

相关问题