我有一个 JavaScript 函数
function $m(theVar){
return document.getElementById(theVar)
}
上面代码的问题是,我想要传递的元素是由ajax生成的,所以我需要类似的东西.live()
在 jquery 中,除非它抛出错误
如何在 jQuery 中重写上述函数,以便以后生成的任何 DOM 元素也可以被检测到。
Update:
当我的页面第一次加载时,它会加载
1) ajaxupload.js 及代码
function ajaxUpload(form,url_action,msg){
var id_element= "pop-con";
function $m(theVar){
return document.getElementById(theVar)
}
if($m(id_element)==null){
erro += "The element of 3rd parameter does not exists.\n";
}
}
2)index.php和代码
<div id="popupMargin">
<div class="close">x</div>
<div id="pop-con"></div>
</div>
<div id="ajaxGenerateMarkUp"></div>
3)现在单击按钮,以下标记将添加到#ajaxGeneratedmarkUp
div(通过ajax生成的标记)
<form onSubmit="return disableForm(this);" action="crop/wizecho_upload.php" method="post" name="f" id="wizecho" enctype="multipart/form-data">
<input id="file" type="file" name="file" onChange="return disableForm(this), ajaxUpload(this.form,'crop/wizecho_upload.php', '<br>Uploading image please wait.....<br>'); return false;"/>
</form>
现在,在更改此输入类型文件时,在 JavaScript 中进行调用。现在它显示了错误。
[注意:我只发布了我认为可能影响我的问题的代码部分]