我使用jquery的ajax控件和php文件,根据通过get请求发送到php文件的信息动态创建字段和下拉列表。我遇到的问题是,当php动态添加表单时,dom不会更新以识别新的dom元素。
加载请求加载动态数据后,我需要jquery继续操作这些新字段,但jquery无法识别新的dom元素,这使得按钮等新dom元素成为静态元素。是的,所有的动态字段都有自己的唯一id/类。
我试过了:
$("body").on("mouseover mouseout", "select", function(e){
$('#filelocations').change(function(){
var urlforcode = this.value;
var codeserial = encodeURIComponent(urlforcode);
$( "#containcontent" ).load("/include/adminarea.php?edittext="+codeserial);
});
<-- generic base code, but it only works some of the time.我的问题是,如何让jquery与初始页面加载时不存在但允许我在通过.load请求动态加载时操作这些数据的元素进行交互?
简单的PHP开关:
<?php
$statevariable = $_GET["stateSELECT"];
switch ($statevariable) {
case "AL":
echo '<p class="errorstyle margintopspacing" style="background:purple; color:white;">Some Pricing Data</p><button id="pricingsystem" class="btn btn-primary" >Click To Start Pricing</button>';
break;
case "AK":
echo "Switch1 ".$_GET["stateSELECT"];
break;
case "AZ":
echo "Switch2 ".$_GET["stateSELECT"];
break;
default:
echo "Switch3 ".$_GET["stateSELECT"];
}
?>简单的Jquery事件:
$('#pricingsystem').click(function(){
console.log('The Stuff');
});发布于 2014-07-30 22:47:23
添加一个在加载文件时执行的回调函数。
$( "#containcontent" ).load("/include/adminarea.php?edittext="+codeserial, function(){
// Stuff that must be done when the file is loaded
});https://stackoverflow.com/questions/25039767
复制相似问题