我有一个包含以下两个div的PHP页面,我正在尝试使用click事件加载内容,然后是条件:
if (ballResult == 'W') { // processing wide
$.ajax({
url: "loads/scorer_soft_load.php #extrWideLoad",
cache: false,
success: function(html) {
$("#scoreBt").html("");
$('#scoreBt').append(html);
}, // call back function after ajax request complete
complete: function() {
}
});
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="extraScoreLoad">
<h3 class="g-m-u-heading" id="extrHeading"><span class="badge badge-secondary">Any extra</span></h3>
<button>nb</button>
</div>
<!------load for wide-------->
<div id="extrWideLoad">
<h3 class="g-m-u-heading" id="extrHeading"><span class="badge badge-secondary">Any extra</span></h3>
<button>w</button>
</div>
&#13;
我正在为其他div做同样的事情,只是将网址更改为loads/scorer_soft_load.php #extraScoreLoad
。
答案 0 :(得分:0)
url: "loads/scorer_soft_load.php #extrWideLoad"
您正在尝试在网址中应用选择器。 (不要与片段标识符混淆。)URL实际上并不像那样工作。它会返回所有内容,您需要在收到内容后应用选择器。例如:
$.ajax({
url: "loads/scorer_soft_load.php",
cache: false,
success: function(html){
$("#scoreBt").html("");
var filteredHtml = $('#extrWideLoad', html); // <--- here
$('#scoreBt').append(filteredHtml);
}
});
我已经在.load中使用了这种技术,并且它已经过去了。
那是因为.load()
does this client-side selector logic for you。