Passing a string in onclick function's attribute of element dynamically created element

后端 未结 8 2284
迷失自我
迷失自我 2021-02-09 00:27

I am trying to pass a string in the onClick event handler function\'s arguments of the dynamically created anchor element, see the fiddle http://jsfiddle.net/shmdhussain/bXYe4/.

8条回答
  •  一个人的身影
    2021-02-09 00:54

    Your problem is, that str+="dd

    ";
    will return a string like "dd

    "
    . This will generate a html like this:

    dd

    In this case, the onclick attribute contains only 'test('.

    Try this:

    str+="dd

    ";

    This will generate a html like this:

    dd

提交回复
热议问题