该视图有一个调用javascript函数的链接
@extends('layouts.main')
@section('content')
<table class="table">
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Opción</th>
</tr>
@foreach ($tasks as $task)
<tr>
<td>{{$task->id}}</td>
<td>{{$task->name}}</td>
<td><a href="javascript:void(0)" onclick="eliminar({{$task->id}})" class="btn btn-danger">Eliminar</a></td>
</tr>
@endforeach
</table>
@stop
Run Code Online (Sandbox Code Playgroud)
这是javascript代码
function eliminar(id){
$.ajax({
type: "DELETE",
url: "task/"+id,
success: function (data) {
console.log(data);
},
error: function (data) {
alert('Error:', data);
}
});
}
Run Code Online (Sandbox Code Playgroud)
并使用ajax调用我想调用我的控制器的destroy方法
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Task;
class TaskController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() …Run Code Online (Sandbox Code Playgroud) 我创建了一个按钮,将 CSS 文件添加到页眉。如何通过第二次单击同一按钮从标题中删除此 CSS?
谢谢
<script>
$(document).ready(function(){
$("#myButton").click(function(){
var ls = document.createElement('link');
ls.rel="stylesheet";
ls.href="myCSSfile.css";
document.getElementsByTagName('head')[0].appendChild(ls);
});
});
</script>
<button id="myButton">Add / Remove</button>
Run Code Online (Sandbox Code Playgroud) 我正在未知页面上做一些复杂的进程间 JS,所以 jquery 是不可能的。如果我有 div 的引用,如何获取 div 中的所有图像?
就像是 :
document.getElementsByTagName("img")
Run Code Online (Sandbox Code Playgroud)
但仅限于 div 内。
我正在尝试迭代一系列元素并为每个元素添加一个事件监听器.
填充数组:
var sliders = [].slice.call(document.getElementsByClassName("sliderControlLi"));
Run Code Online (Sandbox Code Playgroud)
迭代数组:
sliders.forEach(function (i){
addEventListener("click", function(){
console.log("you clicked slider controler " + this.index + "!");
});
});
Run Code Online (Sandbox Code Playgroud)
但是使用这段代码,每当我点击任何一个滑块时,我都会获得多个console.log打印输出 - 一次为阵列中的每个滑块.
我找了类似的问题,但我仍然无法解决这个问题.
谢谢你的帮助!
我会如何popOver表现时,才会有与元素counter后,元素与类名相同的金额?(计数器将包含第一个元素)
示例:(使用counter = 3)
bar
bar
foo
bar
foo
foo
bar <-- PopOver would show up here
bar
bar
foo <-- PopOver would show up here
foo
foo
foo
Run Code Online (Sandbox Code Playgroud)
示例:(使用counter = 2)
bar <-- PopOver would show up here
bar
foo
bar
foo <-- PopOver would show up here
foo
bar <-- PopOver would show up here
bar
bar
foo <-- PopOver would show up here
foo
Run Code Online (Sandbox Code Playgroud)
$(".bar").each(function(){
$(this).append("<div class='popOver'>these would be recommended</div>");
}); …Run Code Online (Sandbox Code Playgroud)我正在尝试创建一个包含字符串中所有锚链接的数组.例如,如果我有一个像下面这样的字符串
<a href="http://google.it>Google</a>
<a href="http://google.com>Google 2</a>
Run Code Online (Sandbox Code Playgroud)
它应该返回一个包含两个元素的数组
我的字符串是从textarea获得的,所以我试过了
var html = $("textarea[name=html]").val();
var links = $(html).find('a').attr('href');
console.log(links);
Run Code Online (Sandbox Code Playgroud)
但是,只显示一个链接(可能是字符串中的第一个链接).我知道我可能需要循环遍历字符串中的所有锚点,但我该怎么做呢?
我有前任的标签。: <label id="labelId" class="control-label col-lg-4">Some text ()</label>, 我怎样才能在刹车中间插入文字,然后清除它?
我试过了 :
$('#labelId').replace("()", "(new)");
Run Code Online (Sandbox Code Playgroud)
但这对我不起作用
我有一个代码:
myarray[150] = 'a';
myarray[80] = 'b';
myarray[122] = 'c';
Run Code Online (Sandbox Code Playgroud)
然后 :
myarray.splice(80, 1);
myarray[80] = 'b';
Run Code Online (Sandbox Code Playgroud)
我的应用程序上面的代码结果是:
[150] ='a'; [80] ='b'; [121] ='c';
我不明白为什么c价值121作为指数.anyonen可以解释我的代码有什么问题吗?
邮政服务有一个API,可让您发送包含包裹重量,旅行信息等的xml请求。它将返回xml响应。
如何处理xml响应?我或者需要在客户端解析xml,或者更可取的是,将xml放入一个可以发送到laravel后端进行解析的变量中。
顺便说一句,我正在使用react和laravel。
getPostagePrice = () => {
fetch('http://production.shippingapis.com/ShippingApi.dll?API=RateV4&XML=<RateV4Request USERID="XXXXXXXXXXX"><PackageID="1ST"><Service>PRIORITY</Service><ZipOrigination>44106</ZipOrigination><ZipDestination>20770</ZipDestination><Pounds>1</Pounds><Ounces>8</Ounces><Container>NONRECTANGULAR</Container><Size>LARGE</Size><Width>15</Width><Length>30</Length><Height>15</Height><Girth>55</Girth></Package></RateV4Request>', {
method: 'get',
}).then((response) => {
console.log(response.text());
}).then(str => (new window.DOMParser()).parseFromString(str, "text/xml")
).then(data => console.log(data));
}
Run Code Online (Sandbox Code Playgroud) 我有这个任务,我应该在复选框格式中创建一个带有表单和项目的"订单"页面.我在javascript中编写了一个函数,将标记复选框的值添加到一起并返回总计.它昨天工作正常,但我可能昨天做了一些事情而没有注意到,它不再添加值.
这是功能:
function totalIt() {
var input = document.getElementsByName("product");
var total = 0;
for (var i = 0; i < input.length; i++) {
if (input[i].checked) {
total += parseFloat(input[i].value);
}
}
document.getElementByName("total").value = "$" + total.toFixed(2);
}Run Code Online (Sandbox Code Playgroud)
Select your items:
<br>
<input name="product" value="3.65" type="checkbox" onclick="totalIt()" /> Item 1 - $3.65
<br>
<input name="product" value="5.50" type="checkbox" onclick="totalIt()" /> Item 2 - $5.50
<br>
<input name="product" value="3.29" type="checkbox" onclick="totalIt()" /> Item 3 - $3.29
<br>
<input name="product" value="7.99" type="checkbox" onclick="totalIt()" /> …Run Code Online (Sandbox Code Playgroud)