我试图将HTML页面中的值传递给JS文件。将HTML中的变量传递给JS文件
HTML部分:
<a href="#" id="pagejs_general_delete_wizardresultid"><i class=" icon-bin" ></i> Delete</a>
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"
});
}
});
});
我不确定我怎么能传递变量wizardresultid
从HTML的JavaScript。我可以找到如何从按钮传递一个函数的例子,但不知道如何从链接中完成它。 此外,我试图在文本中显示wizardresultid
。是这样做的正确方法:
text: "Are you sure you want to delete item with reference" + wizardresultid + "? This can not be undone!"
感谢您的帮助!
其实我不看wizardresultid的任何暗示在你的HTML。但是,这可能是你要找的东西? :http://stackoverflow.com/questions/3273350/jquery-click-pass-parameters-to-user-function – Gimby