Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用开关添加HTML块_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用开关添加HTML块

Javascript 使用开关添加HTML块,javascript,jquery,html,Javascript,Jquery,Html,以下是我在(jquery,html)中尝试做的事情: 这样做的目的是,当我按下开关(基本/高级)时,一块html被添加到现有的html中。在这个新块中,将有另一个开关(少/多),该开关应添加另一个块 然而,我似乎无法(少/多)转换工作。事实上,该函数根本没有运行 与(基本/高级)开关相对应的功能是: var selectInvestment = "basic"; function expandInvestment(){ $("input[type=radio][name=expandIn

以下是我在(jquery,html)中尝试做的事情:

这样做的目的是,当我按下开关(基本/高级)时,一块html被添加到现有的html中。在这个新块中,将有另一个开关(少/多),该开关应添加另一个块

然而,我似乎无法(少/多)转换工作。事实上,该函数根本没有运行

与(基本/高级)开关相对应的功能是:

var selectInvestment = "basic";
function expandInvestment(){
    $("input[type=radio][name=expandInformation]").click(function(){
        selectInvestment = $(this).val();
       var huge = 'huge block of html code in here';
        if(selectInvestment == "advanced"){
            $('.investmentBlock').empty();
            $('.investmentBlock').append(huge);
            expandedExpenses();
        } else if(selectInvestment == "basic"){
            $('.investmentBlock').replaceWith("<...more html code...>");
        }
    });
}
var selectInvestment=“basic”;
职能投资(){
$(“输入[type=radio][name=expandInformation]”。单击(函数(){
选择Investment=$(this.val();
var-hugage='此处包含大量html代码';
如果(选择投资=“高级”){
$('.investmentBlock').empty();
$('.investmentBlock')。追加(巨大);
expandedExpenses();
}else if(选择投资==“基本”){
$('.investmentBlock')。替换为(“”);
}
});
}
少/多开关也类似


这里是JSFIDLE预览

因为要动态添加新的单选按钮,所以需要在

$("input[type=radio][name=expandedExpenses]").click(function(){
变成

$("document").on('click', 'input[type=radio][name=expandedExpenses]', function(){

请参见

请参见控制台
未捕获引用错误:未定义还款选择
,fi itfwiw,您可以通过将html块存储在
标记中来整理代码。然后你就可以用
$('#foo').html()获取文本了谢谢,我不知道你可以这么做。我试了一下,似乎还是不起作用。没关系,我打错了。非常感谢!!