mit*_*h2k 1 html javascript jquery
我正在尝试将值从html页面传递给JS文件.
HTML部分:
<a href="#" id="pagejs_general_delete_wizardresultid"><i class=" icon-bin" ></i> Delete</a>
Run Code Online (Sandbox Code Playgroud)
JS档案:
$('#pagejs_general_delete_wizardresultid').on('click', function() {
swal({
title: "Are you sure?",
text: "Are you sure you want to delete item with reference <wizardresultid here>? This can not be undone!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#EF5350",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm, wizardresultid){
if (isConfirm) {
swal({
title: "Deleted!",
text: "The record has been deleted.",
confirmButtonColor: "#66BB6A",
type: "success"
});
}
else {
swal({
title: "Cancelled",
text: "Nothing has been changed.",
confirmButtonColor: "#2196F3",
type: "error"
});
}
});
});
Run Code Online (Sandbox Code Playgroud)
我不确定如何将变量wizardresultid从HTML传递到javascript.我可以找到如何从按钮传递函数的示例,但不是如何从链接中传递它.此外,我正试图wizardresultid在文本中显示.这是正确的方法:
text: "Are you sure you want to delete item with reference" + wizardresultid + "? This can not be undone!"
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!!!
推荐的'数据'属性.喜欢
<a href="#" id="pagejs_general_delete_wizardresultid" data="your data"><i class=" icon-bin" ></i> Delete</a>
Run Code Online (Sandbox Code Playgroud)
和访问使用:
var val = $('#pagejs_general_delete_wizardresultid').attr('data');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
601 次 |
| 最近记录: |