Php 是否可以在先前执行的jquery的返回结果中执行jquery
我有一个选择框,在更改中使用Php 是否可以在先前执行的jquery的返回结果中执行jquery,php,jquery,Php,Jquery,我有一个选择框,在更改中使用jquery$.post(),用php解析数据,并通过posit.done()返回结果,并将其呈现在指定的div中。这很好 问题在于返回的解析结果中存在一个工具提示类,该类假定在悬停时响应,但没有响应 这是选择框的代码: # selector wrap # ------------------------------------------------ echo '<div class="selector-wrap row">';
jquery$.post()
,用php解析数据,并通过posit.done()
返回结果,并将其呈现在指定的div中。这很好
问题在于返回的解析结果中存在一个工具提示类,该类假定在悬停时响应,但没有响应
这是选择框的代码:
# selector wrap
# ------------------------------------------------
echo '<div class="selector-wrap row">';
echo '<div class="col_12">';
echo '<label>Available Classes</label><br>';
echo '<select id="classCat" name="classCat" class="expand">';
echo '<option value="0">Select Classes Category</option>';
/* loop though classes data files categories to populate options */
foreach(glob($level.'css/classes/data/*.dat') as $file) {
$id = $file;
$title = basename(str_replace("-"," ",str_replace(".dat","",$id)));
echo '<option value="'.$id.'">'.ucwords($title).'</option>';
}
echo '</select>';
echo '</div>';
echo '</div>';
# render desired content
# ------------------------------------------------
echo '<div class="showClasses renderQuery"></div>';
/* parse get special caracters category */
$("#classCat").change(function(){
var id = $(this).val();
var url = siteURL + 'css/classes/parse-class-categories.php';
var postit = $.post( url, {id:id});
postit.done(function( data ) {$('.showClasses').html(data);});
});
<?php
/* get content for this category */
$id = $_POST['id'];
$content = file_get_contents($id);
$cleanit = substr($content, -1); if($cleanit == ','){$content = substr($content, 0, -1);}
/* if no cat selected */
if(empty($id)){echo '';}
/* render selected category */
elseif(!empty($id)){
echo '<div class="slideContnetWrap clearfix">';
/* loop through this category and render classes */
$getClasses = explode("\r",$content);
foreach($getClasses as $getClass){
$pcs = explode("|",$getClass); $this_class = $pcs[0]; $about = $pcs[1];
echo '<div class="col_12">';
echo '<div class="rendered-label" style="font-size: 12px;">';
echo '<span class="tooltip-left" title="'.$about.'"><i class="fa fa-info-circle"></i> </span>';
echo ' <span class="renderHead">'.ucwords(str_replace("-"," ",$this_class)).'</span>';
echo '</div>';
echo '<div class="getItInput">';
echo '<input type"text" class="expand" ';
echo 'onClick="this.setSelectionRange(0, this.value.length);" value="'.$this_class.'">';
echo '</div>';
echo '</div>';
}
echo '</div>';
}
?>
这是解析php文件:
# selector wrap
# ------------------------------------------------
echo '<div class="selector-wrap row">';
echo '<div class="col_12">';
echo '<label>Available Classes</label><br>';
echo '<select id="classCat" name="classCat" class="expand">';
echo '<option value="0">Select Classes Category</option>';
/* loop though classes data files categories to populate options */
foreach(glob($level.'css/classes/data/*.dat') as $file) {
$id = $file;
$title = basename(str_replace("-"," ",str_replace(".dat","",$id)));
echo '<option value="'.$id.'">'.ucwords($title).'</option>';
}
echo '</select>';
echo '</div>';
echo '</div>';
# render desired content
# ------------------------------------------------
echo '<div class="showClasses renderQuery"></div>';
/* parse get special caracters category */
$("#classCat").change(function(){
var id = $(this).val();
var url = siteURL + 'css/classes/parse-class-categories.php';
var postit = $.post( url, {id:id});
postit.done(function( data ) {$('.showClasses').html(data);});
});
<?php
/* get content for this category */
$id = $_POST['id'];
$content = file_get_contents($id);
$cleanit = substr($content, -1); if($cleanit == ','){$content = substr($content, 0, -1);}
/* if no cat selected */
if(empty($id)){echo '';}
/* render selected category */
elseif(!empty($id)){
echo '<div class="slideContnetWrap clearfix">';
/* loop through this category and render classes */
$getClasses = explode("\r",$content);
foreach($getClasses as $getClass){
$pcs = explode("|",$getClass); $this_class = $pcs[0]; $about = $pcs[1];
echo '<div class="col_12">';
echo '<div class="rendered-label" style="font-size: 12px;">';
echo '<span class="tooltip-left" title="'.$about.'"><i class="fa fa-info-circle"></i> </span>';
echo ' <span class="renderHead">'.ucwords(str_replace("-"," ",$this_class)).'</span>';
echo '</div>';
echo '<div class="getItInput">';
echo '<input type"text" class="expand" ';
echo 'onClick="this.setSelectionRange(0, this.value.length);" value="'.$this_class.'">';
echo '</div>';
echo '</div>';
}
echo '</div>';
}
?>
这通常被视为代码注入,不会由任何现代浏览器执行
将呈现/事件逻辑带回JQuery,并使用PHP根据请求提供数据。只要使用浏览器的Javascript引擎进行渲染和事件处理,一切都会好起来。感谢@Steve Harris的响应。。。我得到了代码注入。。。我有点认为这是某种意义上的东西。我不太清楚你的解决方案中的意思。。。如何将呈现/事件逻辑带回jquery。。。您可以解释一下,您正在从PHP返回HTML的动态片段。而是返回JSON或其他一些数据,并使用这些数据使用JQuery/Javascript呈现动态代码段。您可以轻松地在JQuery中构造HTML元素并将它们添加到DOM中。您还可以使用CSS和JQuery方法隐藏/显示元素,只需呈现您需要的所有HTML,但只需隐藏您不使用的部分。有很多方法可以解决这个问题,而不必在服务器端呈现HTML。事实上,使用React和AngularJS等工具,您几乎可以完全使用浏览器端的绑定。谢谢@Steve Harris。。。我明白你的意思。