0

我正在尝试将元素附加到<div>页面的 a,但它不起作用。

第 1 页 (index.php)

<a href=" another.php " id="p1id" type="button">Go to page 2</a>

第2页(另一个.php)

<div id=p2id></a>

JavaScript (jqtest.js)

$.("#p1id").click(function(){
    $.("#p1id").append()
});
4

4 回答 4

5

问题

$.("#p1id").click(function(){
-^here
 $.("#p1id").append()
--^ here
});

去除那个.

于 2012-04-05T20:56:22.363 回答
2

试试这个:

<div id="p2id"></div>

...

$("#p1id").click(function(event){
    $("#p1id").append();
    event.preventDefault();
    return false;
});

此外:

  1. 你需要append一些东西
  2. 看起来您正在使用锚点 ,<a/>作为按钮。您将需要阻止默认操作,即加载页面。
于 2012-04-05T20:56:50.950 回答
0

你也append()没有参数地打电话。它需要一个content论据。

http://api.jquery.com/append/

于 2012-04-05T20:58:02.447 回答
0

如果你的 html 是

<div id="p1id">A div<div>​

你可以追加喜欢

$(function(){
    $('#p1id').click(function(e){
        var myP=$('<p class="myClass">New paragraph</p>');
        $(this).append(myP);
    });
});​

一个例子是here

于 2012-04-05T21:02:56.183 回答