我有一个字符串文件路径,需要通过它传递给jquery函数,它的外观如下。“函数viewDocument(extension,filename,filepath)
上的第三个参数”
<div onclick="viewDocument(doc,APPLICATION FOR POSITION OF HOW2 STUDENT LEADER,/Uploads/2018/Applicant_s219193029/documents/)" class="document info">
<div class="document-body">
<i class="fa fa-file-word-o text-info"></i>
</div>
<div class="document-footer">
<span class="document-name">APPLICATION FOR POSITION OF HOW2 STUDENT LEADER.doc </span> <span class="document-description"> 53KB </span>
</div>
</div>
我一直在尝试修改,没有运气。
答案 0 :(得分:3)
在这种情况下,您可以将它们包装在单引号'
中,因为onclick函数被双引号"
包围
onclick =“ viewDocument('doc','HOW2学生的位置申请 LEADER','/ Uploads / 2018 / Applicant_s219193029 / documents /')“
或者,如果函数用单引号"
包裹,则使用双引号'
onclick ='viewDocument(“ doc”,“ HOW2学生的位置申请 LEADER“,” / Uploads / 2018 / Applicant_s219193029 / documents /“)'
function viewDocument(extension,filename,filepath)
{
console.log(filepath);
}
<div onclick="viewDocument('doc','APPLICATION FOR POSITION OF HOW2 STUDENT LEADER','/Uploads/2018/Applicant_s219193029/documents/')" class="document info">
<div class="document-body">
<i class="fa fa-file-word-o text-info"></i>
</div>
<div class="document-footer">
<span class="document-name">APPLICATION FOR POSITION OF HOW2 STUDENT LEADER.doc </span> <span class="document-description"> 53KB </span>
</div>
</div>