0
我已創建動態<a />
標記與onclick事件和此事件調用一個函數,其中包含一個對象作爲參數,我通過,但onclick鏈接上發生錯誤SyntaxError:預期的表達式,腳本結束了Dynamin創建鏈接傳遞對象作爲參數
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap3-dialog/1.34.7/css/bootstrap-dialog.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap3-dialog/1.34.7/js/bootstrap-dialog.min.js"></script>
<script>
function callconfirm(cb,pmessage)
{
// var isConfirmed
BootstrapDialog.confirm({
title: 'WARNING',
message: pmessage,
type: BootstrapDialog.TYPE_WARNING, // <-- Default value is BootstrapDialog.TYPE_PRIMARY
closable: false, // <-- Default value is false
draggable: false, // <-- Default value is false
btnCancelLabel: 'Do not drop it!', // <-- Default value is 'Cancel',
btnOKLabel: 'Drop it!', // <-- Default value is 'OK',
btnOKClass: 'btn-warning', // <-- If you didn't specify it, dialog type will be used,
callback:cb /*function(result) {
// result will be true if button was click, while it will be false if users close the dialog directly.
if(result) {
return true;
}else {
return false;
}
}*/
});
}
function b1checkConfirm(result,id)
{
//callconfirm();
console.log("B1 click and result is "+result);
console.log(this.p1);
console.log(this.p2);
}
</script>
</head>
<body>
<script type="text/javascript">
document.write('<a href="javascript:void(0)" onClick="javascript:callconfirm(b1checkConfirm.bind({p1: Hello, p2:World}),"Hello")" >Click</a>');
</script>
</body>
您真正需要使用'\'''因爲將document.write'剝去'\」'和代碼將回同樣的問題'onclick'即將結束。 – bobjoe
這可能有效。讓我們讓OP嘗試一下, – Nicolas