简体   繁体   English

使用jQuery附加链接按钮的正确方法是什么

[英]What is the correct way to append a link button using jquery

This is the button I want to append using jquery 这是我要使用jQuery追加的按钮

<a href="{{url('admin/listing/'.$listing->id.'/item/'.$item->id.'/cat_create')}}" class="btn btn-warning">Create</a>

ini jquery code INI jQuery代码

var a = '<a href="{{url('admin/listing/'+data.listing_id+'/item/'+data.id+'/cat_create')}}" class="btn btn-warning">Create</a>'

This line gives me this error Use of undefined constant data - assumed 'data' 这行给我这个错误使用未定义的常量数据-假定为“数据”

I wanted to append this button when I create new entry 我想在创建新条目时附加此按钮

$('#items-list').append(a);

Any ideas which parts of the line cause the error? 有什么想法会导致错误吗?

You can update it directly using the attr method and passing in the attribute you want to modify as well as the value you want to set the attribute to: 您可以使用attr方法直接更新它,并传入要修改的属性以及要将属性设置为的值:

var a = '{{url('admin/listing/'+data.listing_id+'/item/'+data.id+'/cat_create')}}";
$('#items-list').attr( "href", a );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM