在我目前的项目中,我有这样的多行:
$$(document).on('change','#x1', function () {
console.log('fired');
});
$$(document).on('change','#x2', function () {
console.log('fired');
});
$$(document).on('change','#x3', function () {
console.log('fired');
});
Run Code Online (Sandbox Code Playgroud)
是否有可能用一些for循环替换它?(我的例子不起作用)
for (var i = 1; i < 4; i++) {
$$(document).on('change','#x'+i, function () {
});
}
Run Code Online (Sandbox Code Playgroud) 选中一个时,如何禁用其他相同值复选框.
<input type='checkbox' name='check[]' value = '1'>
<input type='checkbox' name='check[]' value = '2'>
<input type='checkbox' name='check[]' value = '1'>
<input type='checkbox' name='check[]' value = '2'>
Run Code Online (Sandbox Code Playgroud) 我需要提供某些角色来访问以下格式的URL:
/connector/{programId}/order/{anything here}
Run Code Online (Sandbox Code Playgroud)
programId整数值在哪里,所以我尝试了以下操作,但它根本不起作用。
/connector/{programId}/order/{anything here}
Run Code Online (Sandbox Code Playgroud)
但是,当我使用它**而不是programId零件时,它运行良好。但是,如何使它与pathVariable(始终为整数)一起使用。
我试图用新的=>表示法将回调绑定到jQuery getJSON命令,但它不起作用.
旧代码(作品)
$.getJSON("js/questions.json", function(data){
console.log("loaded json but lost my scope...");
});
Run Code Online (Sandbox Code Playgroud)
胖箭(不工作)
$.getJSON("js/questions.json", (data) => this.test);
function test(data){
console.log("If we get here we might still have our scope");
}
Run Code Online (Sandbox Code Playgroud) 求和表单元格
<table>
<tr>
<td><input type="text"></td>
<td><input class="price" type="text" value="100"></td>
<td><input class="quantity" type="text" value="2"></td>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
<td><input class="price" type="text" value="100"></td>
<td><input class="quantity" type="text" value="5"></td>
<td><input type="text"></td>
</tr>
<tfoot>
<tr class="summary">
<td>Total:</td>
<td id="total_price"></td>
<td id="total_quantity"></td>
<td class="second"></td>
<td class="third"></td>
</tr>
</tfoot>
</table>
<script>
$(document).ready(function() {
var sum = 0;
var quantity = 0;
$('.price').each(function() {
sum += (parseInt($('.price').val()) * parseInt($('.price').val()));
quantity += parseInt($('.quantity').val();
});
$('#total_price').html(sum);
$('#total_quantity').html(quantity);
})
</script>
Run Code Online (Sandbox Code Playgroud)
输出必须是:总和:700; 总数量:7
我试图降低点击图像的不透明度,但我不知道这是否可能,我可以使用HTML和JavaScript.
所以例如我总共有3个数组,如下所示
var arr1 = ['123','456','789'];
var arr2 = ['435','551','778'];
var arr3 = ['5','7','1'];
Run Code Online (Sandbox Code Playgroud)
我试图将它们存储在一个对象中以供进一步使用.
var Chart = "";
for(var i = 0; i < arr1.length ;i++){
Chart = {
x : arr1[i],
y : arr2[i],
z : arr3[i]
};
}
Run Code Online (Sandbox Code Playgroud)
我的方法完成了这项工作,但是当我控制它并使用它时它只返回最后一组数据.
所以只有 {arr1[2],arr2[2],arr3[2]}用过其余的都没有了.
我怎么能解决这个问题?