我觉得这是一个普遍的问题...但我一直没能找到这个答案...呼叫从一个元素AJAX父页面的功能 - 装载到一个div
我加载当点击一个链接时,使用ajax的一些文本框成一个div内的一个div ...
和在页面的这个新添加的元素的onFocus事件期间,我必须调用父页面中的JavaScript函数...
我的问题是......这些元素......即文本框不能在事件被触发时调用函数.....
个我的猜测是,新加载的元素不会更新到父页面的DOM树
我也使用jQuery的,但离开它一边一段时间,我应该怎么做才能让新加入的元素onFocus将调用写在父页面中的函数..?
这是代码。
<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>
的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>
当文件路径转换功能应该叫...
希望我清楚..
感谢和问候....
我不认为这会将事件绑定到加载到DOM中的未来元素。 – rahul 2009-12-03 05:56:43
谢谢.. 检查绑定是否可以与onchange事件一起工作 – SpikETidE 2009-12-03 06:01:18
Adamantium是正确的...绑定不会在新添加的元素上工作....这就是Live()用于...但live()目前不支持onChange .... 我认为这排除了jquery .... ?? – SpikETidE 2009-12-03 06:40:06