Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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 脚本没有从JSFIDLE运行?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 脚本没有从JSFIDLE运行?

Javascript 脚本没有从JSFIDLE运行?,javascript,jquery,html,Javascript,Jquery,Html,大家好,我刚刚在处理JSFIDLE,但是当我将它加载到脱机.html时,js脚本不会运行吗?这是html文件中的代码,有人知道为什么吗 对不起,我刚开始使用JSFIDLE,不知道为什么我不能在脱机时将我处理的代码复制并粘贴到html文件中,以便进一步处理它 谢谢你的帮助 <body> <table class="table table-striped table-condensed table-bordered"> <thead> <tr>

大家好,我刚刚在处理JSFIDLE,但是当我将它加载到脱机.html时,js脚本不会运行吗?这是html文件中的代码,有人知道为什么吗

对不起,我刚开始使用JSFIDLE,不知道为什么我不能在脱机时将我处理的代码复制并粘贴到html文件中,以便进一步处理它

谢谢你的帮助

<body>
<table class="table table-striped table-condensed table-bordered">
<thead>
    <tr>
        <th>Item</th>
        <th width="20%">Value</th>
        <th width="20%">Quantity</th>
        <th class="actions">Total</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>Item</td>
        <td><input type="hidden" class="input-small" name="var_1" value="60">60</td>
        <td><input type="text" class="input-small" name="var_1_1" value="0"></td>
        <td>$<span class="amount"></span> </td>
    </tr>
    <tr>
        <td>Item</td>
        <td><input type="text" class="input-small" name="var_2" value="0"></td>
        <td><input type="text" class="input-small" name="var_2_2" value="0"></td>
        <td>$<span class="amount"></span> </td>
    </tr>
    <tr>
        <td colspan="3"><strong>Total event cost (viability)</strong></td>
        <td><strong>$<div class="total_amount">total</div></strong></td>
    </tr>
    </tbody></table><button>Go!</button>

<script>
    function doCalc() {
    var total = 0;
    $('tr').each(function() {
        $(this).find('span.amount').html($('input:eq(0)', this).val() * $('input:eq(1)', this).val());
    });
    $('.amount').each(function() {
        total += parseInt($(this).text(),10);
    });
    $('div.total_amount').html(total);
}
$('button').click(doCalc);
</script>
</body>

项目
价值
量
全部的
项目
60
$ 
项目
$ 
活动总成本(可行性)
$total
走!
函数doCalc(){
var合计=0;
$('tr')。每个(函数(){
$(this.find('span.amount').html($('input:eq(0)”,this.val()*$('input:eq(1)”,this.val());
});
$('.amount')。每个(函数(){
total+=parseInt($(this).text(),10);
});
$('div.total_amount').html(总计);
}
$(“按钮”)。单击(doCalc);

您的脚本依赖于jQuery。您的HTML中没有包含jQuery库。然后为它添加另一个脚本元素。

请包括
jQuery

使用
谷歌CDN

<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>


如果您想离线使用它,只需从上面的
src
链接下载它,然后使用它。

您是否包括jQuery库?您必须学习如何使用控制台调试javascript。您应该会看到错误,说明
$
未定义您必须包含jQuery:语法$(…)是此库的典型语法。最好在加载文档后设置事件处理程序<代码>$(函数(){$('button')。单击(doCalc);})您需要从左侧的javascript下拉框中选择jquery库。jsfiddle提供jquery我建议使用
//ajax.googleapis….
而不是
http://ajax.googleapis...
。这样,不管你是在http还是在https上,他说,当他用那个代码创建一个
html
文件时,它就不起作用了。@Novocaine,是的,这确实更好,但我很抱歉,他永远不会使用
https://
,但其他人可能会;-)