Javascript 从加载到div中的ajax元素调用父页面中的函数
我认为这是一个普遍的问题。。。但是我还没有找到答案 单击链接时,我使用ajax将一些文本框加载到页面中的div中 在这个新添加的页面元素的onFocus事件中,我必须调用父页面中的javascript函数 我的问题是。。。。这些元素。。。i、 e触发事件时,文本框无法调用函数 我猜新加载的元素不会更新到父页面的DOM树 我也在使用jquery,但暂时把它放在一边,我应该怎么做才能让新添加的onFocus元素调用在父页面中编写的函数呢 代码在这里Javascript 从加载到div中的ajax元素调用父页面中的函数,javascript,ajax,Javascript,Ajax,我认为这是一个普遍的问题。。。但是我还没有找到答案 单击链接时,我使用ajax将一些文本框加载到页面中的div中 在这个新添加的页面元素的onFocus事件中,我必须调用父页面中的javascript函数 我的问题是。。。。这些元素。。。i、 e触发事件时,文本框无法调用函数 我猜新加载的元素不会更新到父页面的DOM树 我也在使用jquery,但暂时把它放在一边,我应该怎么做才能让新添加的onFocus元素调用在父页面中编写的函数呢 代码在这里 <script type = "text/j
<script type = "text/javascript">
$(document).ready(function(){
// binding elements
$('.formContainer input[type=file]').live('change',function(){
alert("hi"); // here i bind the newly added file chooser
uploadImage();
});
});
</script>
$(文档).ready(函数(){
//结合元素
$('.formContainer输入[type=file]').live('change',function(){
alert(“hi”);//我在这里绑定新添加的文件选择器
上传图像();
});
});
HTML是
<div class="formContainer">
<form name="frmCreateHotel" action="uploadImage.php" method="post">
<table>
<tr>
<td colspan="2">
<div class="elementRow">
Hotel Image
</div>
</td>
<td>
<div class="elementRow" style="height:100px">
<input name="imageToUpload"
id="imageToUpload"
type="file"
size="30"
class="imageSelector"/> // the function should be called during this elements onchange
<input name="oldImageToDelete"
id="oldImageToDelete"
type="hidden" size="50" />
<input type="hidden" name="MAX_FILE_SIZE"
value="2000000" />
<input name="imageDescription"
id="imageDescription"
type="hidden" />
<div class="toolTip image">
<iframe id="uploadedImage"
name="uploadedImage"
src=""
style="width:160px; height:160px;"
frameborder="0"
marginheight="0"
marginwidth="0"></iframe>
</div>
</div>
</td>
</tr>
</table>
</div>
形象酒店
//该函数应在此元素更改期间调用
当文件路径更改时,应调用函数
希望我说得清楚
谢谢和问候 如果您有jQuery,则可以执行以下操作:
function ajaxCallback() {
/* create text boxes */
$('text box selector').bind('focus', functionName);
}
查看更多信息。您可能想考虑使用jQuery来将文本框放入div中。然后您不必担心是否将动态元素正确插入到DOM中。
使其最终工作……/P> 我使用jquery的ajax函数加载html元素,并使用document.getElementbyId()获取对元素的引用
工作起来就像一个魅力 我认为这不会将事件绑定到加载到DOM中的未来元素。谢谢。。正在检查绑定是否能与onchange eventAdamantium一起工作是否正确。。。绑定在新添加的元素上不起作用。。。。这就是Live()的用途。。。但是live()当前不支持onChange。。。。我想这排除了jquery的可能性…?嘿。。!!!Live()适用于“更改”事件。。。。。即使文档中没有提到。。。!!!但我的问题还没有解决。。。!!uploadImage函数无法识别表单:frmCreateHotel,因为它不在DOM树中。。。有没有办法解决这个问题。。。?