可能不是最好的方法; (我知道)但是我在一个非常互动的网站上有几个切换按钮,当切换时加载下面的表单字段和单选按钮;嵌套在div中,所有的切换都以相同的形式拉动 - 我正在寻找一种方法在AJAX调用中编写或拉入下面的内容,或者如果必须的话包括somesort,php或iFrame - 这样我可以更新1个文件,我的所有切换都会反映更新的。倾向于保留大部分当前代码的解决方案,而不是绝对重写所有内容以进行更改。
$(function() {
$('#toggle3').click(function () {
$('.toggle').hide('1000');
$('.toggle').html('<div style="font-size: 12px; color: #000; text-align: left; padding-left: 15px; padding-top: 20px;"><form><br>Back wheel color?<br><input type="radio" name="backwheel" value="Purple"><span style="color: #B500E4"><img src="http://ecx.images-amazon.com/images/I/41S7CRzpV3L._AA160_.jpg" style="max-height: 100px;">Purple</span><br><input type="radio" name="backwheel" value="White">White</br><input type="radio" name="backwheel" value="Light Blue"><span style="color: #74A1C4;">Light Blue</span></br><input type="radio" name="backwheel" value="Blue">Blue</br><input type="radio" name="backwheel" value="Tan">Tan</br><input type="radio" name="backwheel" value="Grey">Grey</br><input type="radio" name="backwheel" value="Pink">Pink</br><input type="radio" name="backwheel" value="Red">Red</br><input type="radio" name="backwheel" value="Yellow">Yellow</br><input type="radio" name="backwheel" value="Black">Black</br><input type="radio" name="backwheel" value="Green"><span style="color:#44CA2C">Green</span></br></form></span></form><br>Front Wheel (if different)<br><form><br>Front wheel color?<br><input type="radio" name="backwheel" value="Purple"><span style="color: #B500E4">Purple</span><br><input type="radio" name="backwheel" value="White">White</br><input type="radio" name="backwheel" value="Light Blue"><span style="color: #74A1C4;">Light Blue</span></br><input type="radio" name="backwheel" value="Blue">Blue</br><input type="radio" name="backwheel" value="Tan">Tan</br><input type="radio" name="backwheel" value="Grey">Grey</br><input type="radio" name="backwheel" value="Pink">Pink</br><input type="radio" name="backwheel" value="Red">Red</br><input type="radio" name="backwheel" value="Yellow">Yellow</br><input type="radio" name="backwheel" value="Black">Black</br><input type="radio" name="backwheel" value="Green"><span style="color:#44CA2C">Green</span></br></form></div><div id="next"><a href="#" id="toggle3">Check Out!<img src="http://northbrooklyncollective.com/wp-content/uploads/2013/11/519629-129_ArrowRight-128.png" class="tool"></a></div>');
$('.toggle').slideToggle('1000');
return false;
});
});
最近的尝试:
$(document).ready(function() {
$('#toggle3').click(function(){
var $tog = $('.toggle');
$.ajax({
url: '/BikeCustom/shine/script.php',
type: 'GET', //this is default anyway, only for verbosity
success: function (fields){
$tog.html(fields);
$tog.slideToggle(1000);
}
});
});
script.php =原始的嵌套div。
jQuery:
<script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
答案 0 :(得分:1)
$('#toggle3').click(function(){
var $tog = $('.toggle');
$tog.hide(1000);
$.ajax({
url: 'path/to/my/script.php',
type: 'GET', //this is default anyway, only for verbosity
success: function (fields){
$tog.html(fields);
$tog.slideToggle(1000);
}
});
});