在将其添加到已存在的内容后,我正在尝试获取一个表单(以回调的HTML形式提供)。添加它不会出现任何问题,表单会正确显示。它由带有id =(placeid +“commentinput”)的回调提供(作为HTML)并添加到页面中。但是,尝试执行$(placeid +“commentinput”)并不会返回正确的jQuery元素(例如,alert(form.tagName)应该返回“FORM”,但总是未定义)。
function click_comment1(urlstr, id) { $.ajax({url: urlstr,success: success_on_get_form(urlstr, id)}); }
function success_on_get_form(urlstr, placeid) {
return function (val) {
$("#" + placeid + "newcomment").html(val.replace("comments_body","body"));
$("#pup").html($("#" + placeid + "comments").html());
var form = jQuery("#" + placeid + "commentinput");
var func = submit_comment(urlstr, placeid);
alert(form.id);
form.bind('submit',func);
} }
我已经尝试过我所知道的其他形式的选择(基本上,.children()。我是jQuery的新手)。我现在已经无助地以各种形式对这个问题进行了4个小时的黑客攻击。我很感激你的帮助,谢谢你。
<form action="" enctype="multipart/form-data" id="1commentinput" method="post">...</form>
这是回调的回报;空间省略了中间部分。
看到的#pup元素是this提供的弹出窗口。
“#”+ placeid +“newcomment”是“#”+ placeid +“comments”中的div。前两个调用看似正确执行,并根据需要在弹出窗口中提供回调。
所有这一切的意图是在此弹出窗口中添加一个表单,然后用于进行第二次回调。
答案 0 :(得分:0)
您的问题很可能归结为您使用无效字符来启动元素ID。
将其更改为以有效字符开头,它应该有效。
http://www.w3.org/TR/html4/types.html#type-id
ID和NAME令牌必须以字母([A-Za-z])开头,后面可以跟任意数量的字母,数字([0-9]),连字符(“ - ”),下划线(“ _“),冒号(”:“)和句号(”。“)。